mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-25 17:36:25 -05:00
Add fsck.mergerfs tool (#1483)
This commit is contained in:
parent
34f07e57f5
commit
77ef88b04c
24 changed files with 12156 additions and 43 deletions
39
src/fs_copyfile.cpp
Normal file
39
src/fs_copyfile.cpp
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue