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.
This commit is contained in:
Antonio SJ Musumeci 2026-11-28 00:41:48 -05:00 • committed by Antonio S. Musumeci
parent c49989b75f
commit e954f42751
5 changed files with 21 additions and 29 deletions

View file

@ -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_);
}

View file

@ -25,16 +25,8 @@
#include <string>
#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);
}

View file

@ -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);
}

View file

@ -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 {} - {}",

View file

@ -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();