From ce17e0b82320d0e906bf21520727e355156b1ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois-Xavier=20Payet?= Date: Thu, 11 Dec 2025 19:18:47 +0100 Subject: [PATCH] CHange formatting and copyright --- src/policy_lup.cpp | 294 ++++++++++++++++++++++----------------------- src/policy_lup.hpp | 77 ++++++------ 2 files changed, 184 insertions(+), 187 deletions(-) diff --git a/src/policy_lup.cpp b/src/policy_lup.cpp index e99bb619..3f6b9562 100644 --- a/src/policy_lup.cpp +++ b/src/policy_lup.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2025, François-Xavier Payet + Copyright (c) 2025, Antonio SJ Musumeci and contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -36,61 +36,61 @@ _action(const Branches::Ptr &branches_, const fs::path &fusepath_, std::vector &paths_) { - int rv; - int error; - fs::info_t info; - Branch *obranch; - - obranch = nullptr; - error = ENOENT; - - uint64_t best_used = 0; - uint64_t best_total = 1; - - for (auto &branch : *branches_) + int rv; + int error; + fs::info_t info; + Branch *obranch; + + obranch = nullptr; + error = ENOENT; + + uint64_t best_used = 0; + uint64_t best_total = 1; + + for (auto &branch : *branches_) + { + if (branch.ro()) + error_and_continue(error, EROFS); + if (!fs::exists(branch.path, fusepath_)) + error_and_continue(error, ENOENT); + rv = fs::info(branch.path, &info); + if (rv < 0) + error_and_continue(error, ENOENT); + if (info.readonly) + error_and_continue(error, EROFS); + + uint64_t used = info.spaceused; + uint64_t total = info.spaceused + info.spaceavail; + if (total == 0) { - if (branch.ro()) - error_and_continue(error, EROFS); - if (!fs::exists(branch.path, fusepath_)) - error_and_continue(error, ENOENT); - rv = fs::info(branch.path, &info); - if (rv < 0) - error_and_continue(error, ENOENT); - if (info.readonly) - error_and_continue(error, EROFS); - - uint64_t used = info.spaceused; - uint64_t total = info.spaceused + info.spaceavail; - if (total == 0) - { - used = 0; - total = 1; - } - - if (obranch == nullptr) - { - best_used = used; - best_total = total; - obranch = &branch; - continue; - } - - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; + used = 0; + total = 1; } if (obranch == nullptr) - return -error; + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } + + unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; + unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; + if (lhs >= rhs) + continue; - paths_.push_back(obranch); + best_used = used; + best_total = total; + obranch = &branch; + } - return 0; + if (obranch == nullptr) + return -error; + + paths_.push_back(obranch); + + return 0; } static int @@ -98,137 +98,137 @@ _search(const Branches::Ptr &branches_, const fs::path &fusepath_, std::vector &paths_) { - int rv; - uint64_t used; - uint64_t avail; - uint64_t best_used = 0; - uint64_t best_total = 1; - Branch *obranch; - - obranch = nullptr; - - for (auto &branch : *branches_) + int rv; + uint64_t used; + uint64_t avail; + uint64_t best_used = 0; + uint64_t best_total = 1; + Branch *obranch; + + obranch = nullptr; + + for (auto &branch : *branches_) + { + if (!fs::exists(branch.path, fusepath_)) + continue; + rv = fs::statvfs_cache_spaceused(branch.path, &used); + if (rv < 0) + continue; + rv = fs::statvfs_cache_spaceavail(branch.path, &avail); + if (rv < 0) + continue; + + uint64_t total = used + avail; + if (total == 0) { - if (!fs::exists(branch.path, fusepath_)) - continue; - rv = fs::statvfs_cache_spaceused(branch.path, &used); - if (rv < 0) - continue; - rv = fs::statvfs_cache_spaceavail(branch.path, &avail); - if (rv < 0) - continue; - - uint64_t total = used + avail; - if (total == 0) - { - used = 0; - total = 1; - } - - if (obranch == nullptr) - { - best_used = used; - best_total = total; - obranch = &branch; - continue; - } - - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; + used = 0; + total = 1; } if (obranch == nullptr) - return -ENOENT; + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } - paths_.push_back(obranch); + unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; + unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; + if (lhs >= rhs) + continue; - return 0; + best_used = used; + best_total = total; + obranch = &branch; + } + + if (obranch == nullptr) + return -ENOENT; + + paths_.push_back(obranch); + + return 0; } static int _create(const Branches::Ptr &branches_, std::vector &paths_) { - int rv; - int error; - fs::info_t info; - Branch *obranch; - - obranch = nullptr; - error = ENOENT; - - uint64_t best_used = 0; - uint64_t best_total = 1; - - for (auto &branch : *branches_) + int rv; + int error; + fs::info_t info; + Branch *obranch; + + obranch = nullptr; + error = ENOENT; + + uint64_t best_used = 0; + uint64_t best_total = 1; + + for (auto &branch : *branches_) + { + if (branch.ro_or_nc()) + error_and_continue(error, EROFS); + rv = fs::info(branch.path, &info); + if (rv < 0) + error_and_continue(error, ENOENT); + if (info.readonly) + error_and_continue(error, EROFS); + if (info.spaceavail < branch.minfreespace()) + error_and_continue(error, ENOSPC); + + uint64_t used = info.spaceused; + uint64_t total = info.spaceused + info.spaceavail; + if (total == 0) { - if (branch.ro_or_nc()) - error_and_continue(error, EROFS); - rv = fs::info(branch.path, &info); - if (rv < 0) - error_and_continue(error, ENOENT); - if (info.readonly) - error_and_continue(error, EROFS); - if (info.spaceavail < branch.minfreespace()) - error_and_continue(error, ENOSPC); - - uint64_t used = info.spaceused; - uint64_t total = info.spaceused + info.spaceavail; - if (total == 0) - { - used = 0; - total = 1; - } - - if (obranch == nullptr) - { - best_used = used; - best_total = total; - obranch = &branch; - continue; - } - - unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; - unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; - if (lhs >= rhs) - continue; - - best_used = used; - best_total = total; - obranch = &branch; + used = 0; + total = 1; } if (obranch == nullptr) - return -error; + { + best_used = used; + best_total = total; + obranch = &branch; + continue; + } + + unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total; + unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total; + if (lhs >= rhs) + continue; + + best_used = used; + best_total = total; + obranch = &branch; + } + + if (obranch == nullptr) + return -error; - paths_.push_back(obranch); + paths_.push_back(obranch); - return 0; + return 0; } int Policy::LUP::Action::operator()(const Branches::Ptr &branches_, const fs::path &fusepath_, std::vector &paths_) const { - return ::_action(branches_, fusepath_, paths_); + return ::_action(branches_, fusepath_, paths_); } int Policy::LUP::Create::operator()(const Branches::Ptr &branches_, const fs::path &fusepath_, std::vector &paths_) const { - return ::_create(branches_, paths_); + return ::_create(branches_, paths_); } int Policy::LUP::Search::operator()(const Branches::Ptr &branches_, const fs::path &fusepath_, std::vector &paths_) const { - return ::_search(branches_, fusepath_, paths_); + return ::_search(branches_, fusepath_, paths_); } diff --git a/src/policy_lup.hpp b/src/policy_lup.hpp index 83d30ffb..25b6be32 100644 --- a/src/policy_lup.hpp +++ b/src/policy_lup.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2025, François-Xavier Payet + Copyright (c) 2025, Antonio SJ Musumeci and contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -22,49 +22,46 @@ namespace Policy { - namespace LUP + namespace LUP + { + class Action final : public Policy::ActionImpl { - class Action final : public Policy::ActionImpl - { - public: - Action() - : Policy::ActionImpl("lup") - { - } + public: + Action() + : Policy::ActionImpl("lup") + {} - public: - int operator()(const Branches::Ptr &, - const fs::path &, - std::vector &) const final; - }; + public: + int operator()(const Branches::Ptr &, + const fs::path &, + std::vector &) const final; + }; - class Create final : public Policy::CreateImpl - { - public: - Create() - : Policy::CreateImpl("lup") - { - } + class Create final : public Policy::CreateImpl + { + public: + Create() + : Policy::CreateImpl("lup") + {} - public: - int operator()(const Branches::Ptr &, - const fs::path &, - std::vector &) const final; - bool path_preserving() const final { return false; } - }; + public: + int operator()(const Branches::Ptr &, + const fs::path &, + std::vector &) const final; + bool path_preserving() const final { return false; } + }; - class Search final : public Policy::SearchImpl - { - public: - Search() - : Policy::SearchImpl("lup") - { - } + class Search final : public Policy::SearchImpl + { + public: + Search() + : Policy::SearchImpl("lup") + {} - public: - int operator()(const Branches::Ptr &, - const fs::path &, - std::vector &) const final; - }; - } + public: + int operator()(const Branches::Ptr &, + const fs::path &, + std::vector &) const final; + }; + } }