From e954f4275124a508b07082d8c0e091fa34ac0e00 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 28 Nov 2026 00:41:48 -0500 Subject: [PATCH] refactor: pass copyfile's cleanup flag as a bool fs::CopyFileFlags is back to a single field since moveonenospc stopped needing no_replace, and copyfile_stage already takes the same flag as a bool. Take a bool in both fs::copyfile overloads too, and drop the FS_COPYFILE_* macros, which nothing uses. --- src/fs_copyfile.cpp | 18 +++++++++--------- src/fs_copyfile.hpp | 22 ++++++++-------------- src/fs_cow.cpp | 4 +--- src/mergerfs_fsck.cpp | 2 +- tests/tests.cpp | 4 ++-- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/fs_copyfile.cpp b/src/fs_copyfile.cpp index 864cab7f..b3257e9e 100644 --- a/src/fs_copyfile.cpp +++ b/src/fs_copyfile.cpp @@ -222,20 +222,20 @@ fs::copyfile_publish(const fs::StagedCopy &staged_, } s64 -fs::copyfile(const int src_fd_, - const fs::path &dst_filepath_, - const fs::CopyFileFlags &flags_) +fs::copyfile(const int src_fd_, + const fs::path &dst_filepath_, + const bool cleanup_failure_) { s64 rv; fs::StagedCopy staged; - rv = fs::copyfile_stage(src_fd_,dst_filepath_,flags_.cleanup_failure,&staged); + rv = fs::copyfile_stage(src_fd_,dst_filepath_,cleanup_failure_,&staged); if(rv < 0) return rv; DEFER { fs::close(staged.fd); }; rv = fs::rename(staged.path.c_str(),dst_filepath_.c_str()); - if((rv < 0) && (flags_.cleanup_failure)) + if((rv < 0) && cleanup_failure_) fs::unlink(staged.path); return rv; @@ -247,9 +247,9 @@ fs::copyfile(const int src_fd_, #endif s64 -fs::copyfile(const fs::path &src_filepath_, - const fs::path &dst_filepath_, - const fs::CopyFileFlags &flags_) +fs::copyfile(const fs::path &src_filepath_, + const fs::path &dst_filepath_, + const bool cleanup_failure_) { int src_fd; @@ -258,5 +258,5 @@ fs::copyfile(const fs::path &src_filepath_, return src_fd; DEFER { fs::close(src_fd); }; - return fs::copyfile(src_fd,dst_filepath_,flags_); + return fs::copyfile(src_fd,dst_filepath_,cleanup_failure_); } diff --git a/src/fs_copyfile.hpp b/src/fs_copyfile.hpp index 51336cec..0ad4e43f 100644 --- a/src/fs_copyfile.hpp +++ b/src/fs_copyfile.hpp @@ -25,16 +25,8 @@ #include -#define FS_COPYFILE_NONE (0) -#define FS_COPYFILE_CLEANUP_FAILURE (1 << 0) - namespace fs { - struct CopyFileFlags - { - int cleanup_failure:1; - }; - // A copy at a temporary name beside its destination. While fd is // open it pins the copied object, whatever its name. src_st is the // source as it was when copied. @@ -66,13 +58,15 @@ namespace fs copyfile_publish(const StagedCopy &staged, const fs::path &dst_filepath); + // Copy to dst_filepath, replacing it. The copy is staged as above; + // on failure the temporary is removed when cleanup_failure is set. s64 - copyfile(const int src_fd, - const fs::path &dst_filepath, - const CopyFileFlags &flags); + copyfile(const int src_fd, + const fs::path &dst_filepath, + const bool cleanup_failure); s64 - copyfile(const fs::path &src_filepath, - const fs::path &dst_filepath, - const CopyFileFlags &flags); + copyfile(const fs::path &src_filepath, + const fs::path &dst_filepath, + const bool cleanup_failure); } diff --git a/src/fs_cow.cpp b/src/fs_cow.cpp index 18aafea8..4f70c8fc 100644 --- a/src/fs_cow.cpp +++ b/src/fs_cow.cpp @@ -72,7 +72,5 @@ fs::cow::is_eligible(const fs::path &fullpath_, int fs::cow::break_link(const fs::path &src_filepath_) { - return fs::copyfile(src_filepath_, - src_filepath_, - { .cleanup_failure = true }); + return fs::copyfile(src_filepath_,src_filepath_,true); } diff --git a/src/mergerfs_fsck.cpp b/src/mergerfs_fsck.cpp index 73f9c208..d81efa59 100644 --- a/src/mergerfs_fsck.cpp +++ b/src/mergerfs_fsck.cpp @@ -252,7 +252,7 @@ _copy_files(const std::string &src_, if(fs::is_same_file(src_,dst.path) == 1) continue; - rv = fs::copyfile(src_,dst.path,{.cleanup_failure=false}); + rv = fs::copyfile(src_,dst.path,false); if(rv < 0) fmt::print(stderr, "ERROR: failed copying to {} - {}", diff --git a/tests/tests.cpp b/tests/tests.cpp index 094a9ab3..f786fbc8 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -3946,7 +3946,7 @@ test_fs_copyfile_basic() rv = ::pwrite(src_fd,"Z",1,((16 * 1024 * 1024) - 1)); TEST_CHECK(rv == 1); - rv = fs::copyfile(src_fd,dst_path,{.cleanup_failure = true}); + rv = fs::copyfile(src_fd,dst_path,true); TEST_CHECK(rv == 0); rv = ::fstat(src_fd,&st); @@ -4022,7 +4022,7 @@ test_fs_copyfile_source_changes_cleanup_tmpfiles() } }); - rv = fs::copyfile(src_fd,dst_path,{.cleanup_failure = true}); + rv = fs::copyfile(src_fd,dst_path,true); stop_mutator.store(true); mutator.join();