Add fsck.mergerfs tool (#1483)

This commit is contained in:
trapexit 2025-06-23 21:57:55 -05:00 • committed by GitHub
parent 34f07e57f5
commit 77ef88b04c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 12156 additions and 43 deletions

39
src/fs_copyfile.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "fs_copyfile.hpp"
#include "fs_clonefile.hpp"
#include "fs_close.hpp"
#include "fs_mktemp.hpp"
#include "fs_open.hpp"
#include "fs_rename.hpp"
#include "scope_guard.hpp"
#include <fcntl.h>
int
fs::copyfile(const std::filesystem::path &src_,
const std::filesystem::path &dst_)
{
int rv;
int src_fd;
int dst_fd;
std::string dst_tmppath;
src_fd = fs::open(src_,O_RDONLY|O_NOFOLLOW);
if(src_fd < 0)
return src_fd;
DEFER { fs::close(src_fd); };
std::tie(dst_fd,dst_tmppath) = fs::mktemp(dst_,O_RDWR);
if(dst_fd < 0)
return dst_fd;
DEFER { fs::close(dst_fd); };
rv = fs::clonefile(src_fd,dst_fd);
if(rv < 0)
return rv;
rv = fs::rename(dst_tmppath,dst_);
return rv;
}