|
@ -35,7 +35,6 @@ |
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
|
|
namespace gfs = ghc::filesystem; |
|
|
namespace gfs = ghc::filesystem; |
|
|
|
|
|
|
|
|
namespace error |
|
|
namespace error |
|
@ -62,12 +61,12 @@ namespace l |
|
|
{ |
|
|
{ |
|
|
static |
|
|
static |
|
|
bool |
|
|
bool |
|
|
contains(const StrVec &haystack_, |
|
|
|
|
|
|
|
|
contains(const std::vector<Branch*> &haystack_, |
|
|
const char *needle_) |
|
|
const char *needle_) |
|
|
{ |
|
|
{ |
|
|
for(auto &hay : haystack_) |
|
|
for(auto &hay : haystack_) |
|
|
{ |
|
|
{ |
|
|
if(hay == needle_) |
|
|
|
|
|
|
|
|
if(hay->path == needle_) |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -76,8 +75,8 @@ namespace l |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
bool |
|
|
bool |
|
|
contains(const StrVec &haystack_, |
|
|
|
|
|
const string &needle_) |
|
|
|
|
|
|
|
|
contains(const std::vector<Branch*> &haystack_, |
|
|
|
|
|
const std::string &needle_) |
|
|
{ |
|
|
{ |
|
|
return l::contains(haystack_,needle_.c_str()); |
|
|
return l::contains(haystack_,needle_.c_str()); |
|
|
} |
|
|
} |
|
@ -90,41 +89,27 @@ namespace l |
|
|
fs::remove(path); |
|
|
fs::remove(path); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
void |
|
|
|
|
|
remove(const Branches::CPtr &branches_, |
|
|
|
|
|
const std::string &relpath_) |
|
|
|
|
|
{ |
|
|
|
|
|
std::string fullpath; |
|
|
|
|
|
|
|
|
|
|
|
for(auto &branch : *branches_) |
|
|
|
|
|
{ |
|
|
|
|
|
fullpath = fs::path::make(branch.path,relpath_); |
|
|
|
|
|
fs::remove(fullpath); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
int |
|
|
int |
|
|
rename_create_path(const Policy::Search &searchPolicy_, |
|
|
rename_create_path(const Policy::Search &searchPolicy_, |
|
|
const Policy::Action &actionPolicy_, |
|
|
const Policy::Action &actionPolicy_, |
|
|
const Branches::CPtr &branches_, |
|
|
|
|
|
|
|
|
const Branches::Ptr &branches_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &newfusepath_) |
|
|
const gfs::path &newfusepath_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
int error; |
|
|
int error; |
|
|
StrVec toremove; |
|
|
StrVec toremove; |
|
|
StrVec newbasepath; |
|
|
|
|
|
StrVec oldbasepaths; |
|
|
|
|
|
|
|
|
std::vector<Branch*> newbranches; |
|
|
|
|
|
std::vector<Branch*> oldbranches; |
|
|
gfs::path oldfullpath; |
|
|
gfs::path oldfullpath; |
|
|
gfs::path newfullpath; |
|
|
gfs::path newfullpath; |
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths); |
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,oldbranches); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
|
rv = searchPolicy_(branches_,newfusepath_.parent_path(),&newbasepath); |
|
|
|
|
|
|
|
|
rv = searchPolicy_(branches_,newfusepath_.parent_path(),newbranches); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
@ -134,7 +119,7 @@ namespace l |
|
|
newfullpath = branch.path; |
|
|
newfullpath = branch.path; |
|
|
newfullpath += newfusepath_; |
|
|
newfullpath += newfusepath_; |
|
|
|
|
|
|
|
|
if(!l::contains(oldbasepaths,branch.path)) |
|
|
|
|
|
|
|
|
if(!l::contains(oldbranches,branch.path)) |
|
|
{ |
|
|
{ |
|
|
toremove.push_back(newfullpath); |
|
|
toremove.push_back(newfullpath); |
|
|
continue; |
|
|
continue; |
|
@ -146,7 +131,9 @@ namespace l |
|
|
rv = fs::rename(oldfullpath,newfullpath); |
|
|
rv = fs::rename(oldfullpath,newfullpath); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
{ |
|
|
{ |
|
|
rv = fs::clonepath_as_root(newbasepath[0],branch.path,newfusepath_.parent_path()); |
|
|
|
|
|
|
|
|
rv = fs::clonepath_as_root(newbranches[0]->path, |
|
|
|
|
|
branch.path, |
|
|
|
|
|
newfusepath_.parent_path()); |
|
|
if(rv == 0) |
|
|
if(rv == 0) |
|
|
rv = fs::rename(oldfullpath,newfullpath); |
|
|
rv = fs::rename(oldfullpath,newfullpath); |
|
|
} |
|
|
} |
|
@ -165,18 +152,18 @@ namespace l |
|
|
static |
|
|
static |
|
|
int |
|
|
int |
|
|
rename_preserve_path(const Policy::Action &actionPolicy_, |
|
|
rename_preserve_path(const Policy::Action &actionPolicy_, |
|
|
const Branches::CPtr &branches_, |
|
|
|
|
|
|
|
|
const Branches::Ptr &branches_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &newfusepath_) |
|
|
const gfs::path &newfusepath_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
bool success; |
|
|
bool success; |
|
|
StrVec toremove; |
|
|
StrVec toremove; |
|
|
StrVec oldbasepaths; |
|
|
|
|
|
|
|
|
std::vector<Branch*> oldbranches; |
|
|
gfs::path oldfullpath; |
|
|
gfs::path oldfullpath; |
|
|
gfs::path newfullpath; |
|
|
gfs::path newfullpath; |
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths); |
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,oldbranches); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
@ -186,7 +173,7 @@ namespace l |
|
|
newfullpath = branch.path; |
|
|
newfullpath = branch.path; |
|
|
newfullpath += newfusepath_; |
|
|
newfullpath += newfusepath_; |
|
|
|
|
|
|
|
|
if(!l::contains(oldbasepaths,branch.path)) |
|
|
|
|
|
|
|
|
if(!l::contains(oldbranches,branch.path)) |
|
|
{ |
|
|
{ |
|
|
toremove.push_back(newfullpath); |
|
|
toremove.push_back(newfullpath); |
|
|
continue; |
|
|
continue; |
|
@ -216,19 +203,19 @@ namespace l |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
rename_exdev_rename_back(const StrVec &basepaths_, |
|
|
|
|
|
|
|
|
rename_exdev_rename_back(const std::vector<Branch*> &branches_, |
|
|
const gfs::path &oldfusepath_) |
|
|
const gfs::path &oldfusepath_) |
|
|
{ |
|
|
{ |
|
|
gfs::path oldpath; |
|
|
gfs::path oldpath; |
|
|
gfs::path newpath; |
|
|
gfs::path newpath; |
|
|
|
|
|
|
|
|
for(auto &basepath : basepaths_) |
|
|
|
|
|
|
|
|
for(auto &branch : branches_) |
|
|
{ |
|
|
{ |
|
|
oldpath = basepath; |
|
|
|
|
|
|
|
|
oldpath = branch->path; |
|
|
oldpath /= ".mergerfs_rename_exdev"; |
|
|
oldpath /= ".mergerfs_rename_exdev"; |
|
|
oldpath += oldfusepath_; |
|
|
oldpath += oldfusepath_; |
|
|
|
|
|
|
|
|
newpath = basepath; |
|
|
|
|
|
|
|
|
newpath = branch->path; |
|
|
newpath += oldfusepath_; |
|
|
newpath += oldfusepath_; |
|
|
|
|
|
|
|
|
fs::rename(oldpath,newpath); |
|
|
fs::rename(oldpath,newpath); |
|
@ -238,23 +225,23 @@ namespace l |
|
|
static |
|
|
static |
|
|
int |
|
|
int |
|
|
rename_exdev_rename_target(const Policy::Action &actionPolicy_, |
|
|
rename_exdev_rename_target(const Policy::Action &actionPolicy_, |
|
|
const Branches::CPtr &branches_, |
|
|
|
|
|
|
|
|
const Branches::Ptr &ibranches_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &oldfusepath_, |
|
|
StrVec *basepaths_) |
|
|
|
|
|
|
|
|
std::vector<Branch*> &obranches_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
gfs::path clonesrc; |
|
|
gfs::path clonesrc; |
|
|
gfs::path clonetgt; |
|
|
gfs::path clonetgt; |
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,basepaths_); |
|
|
|
|
|
|
|
|
rv = actionPolicy_(ibranches_,oldfusepath_,obranches_); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
|
ugid::SetRootGuard ugidGuard; |
|
|
ugid::SetRootGuard ugidGuard; |
|
|
for(auto &basepath : *basepaths_) |
|
|
|
|
|
|
|
|
for(auto &branch : obranches_) |
|
|
{ |
|
|
{ |
|
|
clonesrc = basepath; |
|
|
|
|
|
clonetgt = basepath; |
|
|
|
|
|
|
|
|
clonesrc = branch->path; |
|
|
|
|
|
clonetgt = branch->path; |
|
|
clonetgt /= ".mergerfs_rename_exdev"; |
|
|
clonetgt /= ".mergerfs_rename_exdev"; |
|
|
|
|
|
|
|
|
rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path()); |
|
|
rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path()); |
|
@ -278,7 +265,7 @@ namespace l |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
error: |
|
|
error: |
|
|
l::rename_exdev_rename_back(*basepaths_,oldfusepath_); |
|
|
|
|
|
|
|
|
l::rename_exdev_rename_back(obranches_,oldfusepath_); |
|
|
|
|
|
|
|
|
return -EXDEV; |
|
|
return -EXDEV; |
|
|
} |
|
|
} |
|
@ -286,16 +273,16 @@ namespace l |
|
|
static |
|
|
static |
|
|
int |
|
|
int |
|
|
rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, |
|
|
rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, |
|
|
const Branches::CPtr &branches_, |
|
|
|
|
|
|
|
|
const Branches::Ptr &branches_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &newfusepath_) |
|
|
const gfs::path &newfusepath_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
StrVec basepaths; |
|
|
|
|
|
gfs::path target; |
|
|
gfs::path target; |
|
|
gfs::path linkpath; |
|
|
gfs::path linkpath; |
|
|
|
|
|
std::vector<Branch*> branches; |
|
|
|
|
|
|
|
|
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths); |
|
|
|
|
|
|
|
|
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); |
|
|
if(rv < 0) |
|
|
if(rv < 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
@ -306,7 +293,7 @@ namespace l |
|
|
|
|
|
|
|
|
rv = FUSE::symlink(target.c_str(),linkpath.c_str()); |
|
|
rv = FUSE::symlink(target.c_str(),linkpath.c_str()); |
|
|
if(rv < 0) |
|
|
if(rv < 0) |
|
|
l::rename_exdev_rename_back(basepaths,oldfusepath_); |
|
|
|
|
|
|
|
|
l::rename_exdev_rename_back(branches,oldfusepath_); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
@ -314,17 +301,17 @@ namespace l |
|
|
static |
|
|
static |
|
|
int |
|
|
int |
|
|
rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, |
|
|
rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, |
|
|
const Branches::CPtr &branches_, |
|
|
|
|
|
|
|
|
const Branches::Ptr &branches_, |
|
|
const gfs::path &mount_, |
|
|
const gfs::path &mount_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &oldfusepath_, |
|
|
const gfs::path &newfusepath_) |
|
|
const gfs::path &newfusepath_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
StrVec basepaths; |
|
|
|
|
|
gfs::path target; |
|
|
gfs::path target; |
|
|
gfs::path linkpath; |
|
|
gfs::path linkpath; |
|
|
|
|
|
std::vector<Branch*> branches; |
|
|
|
|
|
|
|
|
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths); |
|
|
|
|
|
|
|
|
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); |
|
|
if(rv < 0) |
|
|
if(rv < 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
@ -335,7 +322,7 @@ namespace l |
|
|
|
|
|
|
|
|
rv = FUSE::symlink(target.c_str(),linkpath.c_str()); |
|
|
rv = FUSE::symlink(target.c_str(),linkpath.c_str()); |
|
|
if(rv < 0) |
|
|
if(rv < 0) |
|
|
l::rename_exdev_rename_back(basepaths,oldfusepath_); |
|
|
|
|
|
|
|
|
l::rename_exdev_rename_back(branches,oldfusepath_); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|