Fix rename path generation (#1540)
Some checks failed
CodeQL / Analyze (push) Has been cancelled
mkdocs / deploy (push) Has been cancelled

This commit is contained in:
trapexit 2025-10-01 18:47:13 -04:00 • committed by GitHub
parent 25b0bc72df
commit 3cb35a3a65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,8 +92,7 @@ _rename_create_path(const Policy::Search &searchPolicy_,
for(auto &branch : *branches_) for(auto &branch : *branches_)
{ {
newfullpath = branch.path; newfullpath = branch.path / newfusepath_;
newfullpath += newfusepath_;
if(!::_contains(oldbranches,branch.path)) if(!::_contains(oldbranches,branch.path))
{ {
@ -101,8 +100,7 @@ _rename_create_path(const Policy::Search &searchPolicy_,
continue; continue;
} }
oldfullpath = branch.path; oldfullpath = branch.path / oldfusepath_;
oldfullpath += oldfusepath_;
rv = fs::rename(oldfullpath,newfullpath); rv = fs::rename(oldfullpath,newfullpath);
if(rv < 0) if(rv < 0)
@ -146,8 +144,7 @@ _rename_preserve_path(const Policy::Action &actionPolicy_,
success = false; success = false;
for(auto &branch : *branches_) for(auto &branch : *branches_)
{ {
newfullpath = branch.path; newfullpath = branch.path / newfusepath_;
newfullpath += newfusepath_;
if(!::_contains(oldbranches,branch.path)) if(!::_contains(oldbranches,branch.path))
{ {
@ -155,8 +152,7 @@ _rename_preserve_path(const Policy::Action &actionPolicy_,
continue; continue;
} }
oldfullpath = branch.path; oldfullpath = branch.path / oldfusepath_;
oldfullpath += oldfusepath_;
rv = fs::rename(oldfullpath,newfullpath); rv = fs::rename(oldfullpath,newfullpath);
if(rv < 0) if(rv < 0)
@ -189,10 +185,10 @@ _rename_exdev_rename_back(const std::vector<Branch*> &branches_,
{ {
oldpath = branch->path; oldpath = branch->path;
oldpath /= ".mergerfs_rename_exdev"; oldpath /= ".mergerfs_rename_exdev";
oldpath += oldfusepath_; oldpath /= oldfusepath_;
newpath = branch->path; newpath = branch->path;
newpath += oldfusepath_; newpath /= oldfusepath_;
fs::rename(oldpath,newpath); fs::rename(oldpath,newpath);
} }
@ -207,7 +203,7 @@ _rename_exdev_rename_target(const Policy::Action &actionPolicy_,
{ {
int rv; int rv;
fs::path clonesrc; fs::path clonesrc;
fs::path clonetgt; fs::path clonedst;
rv = actionPolicy_(ibranches_,oldfusepath_,obranches_); rv = actionPolicy_(ibranches_,oldfusepath_,obranches_);
if(rv < 0) if(rv < 0)
@ -217,23 +213,23 @@ _rename_exdev_rename_target(const Policy::Action &actionPolicy_,
for(auto &branch : obranches_) for(auto &branch : obranches_)
{ {
clonesrc = branch->path; clonesrc = branch->path;
clonetgt = branch->path; clonedst = branch->path;
clonetgt /= ".mergerfs_rename_exdev"; clonedst /= ".mergerfs_rename_exdev";
rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path()); rv = fs::clonepath(clonesrc,clonedst,oldfusepath_.parent_path());
if(rv == -ENOENT) if(rv == -ENOENT)
{ {
fs::mkdir(clonetgt,01777); fs::mkdir(clonedst,01777);
rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path()); rv = fs::clonepath(clonesrc,clonedst,oldfusepath_.parent_path());
} }
if(rv < 0) if(rv < 0)
goto error; goto error;
clonesrc += oldfusepath_; clonesrc /= oldfusepath_;
clonetgt += oldfusepath_; clonedst /= oldfusepath_;
rv = fs::rename(clonesrc,clonetgt); rv = fs::rename(clonesrc,clonedst);
if(rv < 0) if(rv < 0)
goto error; goto error;
} }
@ -264,7 +260,7 @@ _rename_exdev_rel_symlink(const Policy::Action &actionPolicy_,
linkpath = newfusepath_; linkpath = newfusepath_;
target = "/.mergerfs_rename_exdev"; target = "/.mergerfs_rename_exdev";
target += oldfusepath_; target /= oldfusepath_;
target = target.lexically_relative(linkpath.parent_path()); target = target.lexically_relative(linkpath.parent_path());
rv = FUSE::symlink(target.c_str(),linkpath); rv = FUSE::symlink(target.c_str(),linkpath);
@ -294,7 +290,7 @@ _rename_exdev_abs_symlink(const Policy::Action &actionPolicy_,
linkpath = newfusepath_; linkpath = newfusepath_;
target = mount_; target = mount_;
target /= ".mergerfs_rename_exdev"; target /= ".mergerfs_rename_exdev";
target += oldfusepath_; target /= oldfusepath_;
rv = FUSE::symlink(target.c_str(),linkpath); rv = FUSE::symlink(target.c_str(),linkpath);
if(rv < 0) if(rv < 0)