|
@ -38,10 +38,16 @@ using namespace mergerfs; |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
bool |
|
|
bool |
|
|
member(const vector<string> &haystack, |
|
|
|
|
|
|
|
|
member(const vector<const string*> &haystack, |
|
|
const string &needle) |
|
|
const string &needle) |
|
|
{ |
|
|
{ |
|
|
return (std::find(haystack.begin(),haystack.end(),needle) != haystack.end()); |
|
|
|
|
|
|
|
|
for(size_t i = 0, ei = haystack.size(); i != ei; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(*haystack[i] == needle) |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
@ -54,11 +60,11 @@ _remove(const vector<string> &toremove) |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
_rename_create_path_one(const vector<string> &oldbasepaths, |
|
|
|
|
|
|
|
|
_rename_create_path_core(const vector<const string*> &oldbasepaths, |
|
|
const string &oldbasepath, |
|
|
const string &oldbasepath, |
|
|
const string &newbasepath, |
|
|
const string &newbasepath, |
|
|
const string &oldfusepath, |
|
|
|
|
|
const string &newfusepath, |
|
|
|
|
|
|
|
|
const char *oldfusepath, |
|
|
|
|
|
const char *newfusepath, |
|
|
const string &newfusedirpath, |
|
|
const string &newfusedirpath, |
|
|
int &error, |
|
|
int &error, |
|
|
vector<string> &tounlink) |
|
|
vector<string> &tounlink) |
|
@ -68,7 +74,7 @@ _rename_create_path_one(const vector<string> &oldbasepaths, |
|
|
string oldfullpath; |
|
|
string oldfullpath; |
|
|
string newfullpath; |
|
|
string newfullpath; |
|
|
|
|
|
|
|
|
fs::path::make(oldbasepath,newfusepath,newfullpath); |
|
|
|
|
|
|
|
|
fs::path::make(&oldbasepath,newfusepath,newfullpath); |
|
|
|
|
|
|
|
|
ismember = member(oldbasepaths,oldbasepath); |
|
|
ismember = member(oldbasepaths,oldbasepath); |
|
|
if(ismember) |
|
|
if(ismember) |
|
@ -76,10 +82,10 @@ _rename_create_path_one(const vector<string> &oldbasepaths, |
|
|
if(oldbasepath != newbasepath) |
|
|
if(oldbasepath != newbasepath) |
|
|
{ |
|
|
{ |
|
|
const ugid::SetRootGuard ugidGuard; |
|
|
const ugid::SetRootGuard ugidGuard; |
|
|
fs::clonepath(newbasepath,oldbasepath,newfusedirpath); |
|
|
|
|
|
|
|
|
fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fs::path::make(oldbasepath,oldfusepath,oldfullpath); |
|
|
|
|
|
|
|
|
fs::path::make(&oldbasepath,oldfusepath,oldfullpath); |
|
|
|
|
|
|
|
|
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); |
|
|
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); |
|
|
error = calc_error(rv,error,errno); |
|
|
error = calc_error(rv,error,errno); |
|
@ -98,21 +104,22 @@ _rename_create_path(Policy::Func::Search searchFunc, |
|
|
Policy::Func::Action actionFunc, |
|
|
Policy::Func::Action actionFunc, |
|
|
const vector<string> &srcmounts, |
|
|
const vector<string> &srcmounts, |
|
|
const size_t minfreespace, |
|
|
const size_t minfreespace, |
|
|
const string &oldfusepath, |
|
|
|
|
|
const string &newfusepath) |
|
|
|
|
|
|
|
|
const char *oldfusepath, |
|
|
|
|
|
const char *newfusepath) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
int error; |
|
|
int error; |
|
|
string newbasepath; |
|
|
|
|
|
vector<string> toremove; |
|
|
vector<string> toremove; |
|
|
vector<string> oldbasepaths; |
|
|
|
|
|
|
|
|
vector<const string*> newbasepath; |
|
|
|
|
|
vector<const string*> oldbasepaths; |
|
|
|
|
|
|
|
|
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); |
|
|
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
|
const string newfusedirpath = fs::path::dirname(newfusepath); |
|
|
|
|
|
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); |
|
|
|
|
|
|
|
|
string newfusedirpath = newfusepath; |
|
|
|
|
|
fs::path::dirname(newfusedirpath); |
|
|
|
|
|
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -errno; |
|
|
return -errno; |
|
|
|
|
|
|
|
@ -121,7 +128,8 @@ _rename_create_path(Policy::Func::Search searchFunc, |
|
|
{ |
|
|
{ |
|
|
const string &oldbasepath = srcmounts[i]; |
|
|
const string &oldbasepath = srcmounts[i]; |
|
|
|
|
|
|
|
|
_rename_create_path_one(oldbasepaths,oldbasepath,newbasepath, |
|
|
|
|
|
|
|
|
_rename_create_path_core(oldbasepaths, |
|
|
|
|
|
oldbasepath,*newbasepath[0], |
|
|
oldfusepath,newfusepath, |
|
|
oldfusepath,newfusepath, |
|
|
newfusedirpath, |
|
|
newfusedirpath, |
|
|
error,toremove); |
|
|
error,toremove); |
|
@ -140,25 +148,25 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc, |
|
|
const vector<string> &srcmounts, |
|
|
const vector<string> &srcmounts, |
|
|
const size_t minfreespace, |
|
|
const size_t minfreespace, |
|
|
const string &oldbasepath, |
|
|
const string &oldbasepath, |
|
|
const string &oldfusepath, |
|
|
|
|
|
const string &newfusepath) |
|
|
|
|
|
|
|
|
const char *oldfusepath, |
|
|
|
|
|
const char *newfusepath) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
string newbasepath; |
|
|
|
|
|
string newfusedirpath; |
|
|
string newfusedirpath; |
|
|
|
|
|
vector<const string*> newbasepath; |
|
|
|
|
|
|
|
|
newfusedirpath = fs::path::dirname(newfusepath); |
|
|
|
|
|
|
|
|
|
|
|
rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); |
|
|
|
|
|
|
|
|
newfusedirpath = newfusepath; |
|
|
|
|
|
fs::path::dirname(newfusedirpath); |
|
|
|
|
|
rv = createFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
{ |
|
|
{ |
|
|
if(oldbasepath == newbasepath) |
|
|
|
|
|
|
|
|
if(oldbasepath == *newbasepath[0]) |
|
|
{ |
|
|
{ |
|
|
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); |
|
|
|
|
|
|
|
|
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
{ |
|
|
{ |
|
|
const ugid::SetRootGuard ugidGuard; |
|
|
const ugid::SetRootGuard ugidGuard; |
|
|
fs::clonepath(newbasepath,oldbasepath,newfusedirpath); |
|
|
|
|
|
|
|
|
fs::clonepath(*newbasepath[0],oldbasepath,newfusedirpath.c_str()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
@ -173,14 +181,14 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc, |
|
|
|
|
|
|
|
|
static |
|
|
static |
|
|
void |
|
|
void |
|
|
_rename_preserve_path_one(Policy::Func::Search searchFunc, |
|
|
|
|
|
|
|
|
_rename_preserve_path_core(Policy::Func::Search searchFunc, |
|
|
Policy::Func::Create createFunc, |
|
|
Policy::Func::Create createFunc, |
|
|
const vector<string> &srcmounts, |
|
|
const vector<string> &srcmounts, |
|
|
const size_t minfreespace, |
|
|
const size_t minfreespace, |
|
|
const vector<string> &oldbasepaths, |
|
|
|
|
|
|
|
|
const vector<const string*> &oldbasepaths, |
|
|
const string &oldbasepath, |
|
|
const string &oldbasepath, |
|
|
const string &oldfusepath, |
|
|
|
|
|
const string &newfusepath, |
|
|
|
|
|
|
|
|
const char *oldfusepath, |
|
|
|
|
|
const char *newfusepath, |
|
|
int &error, |
|
|
int &error, |
|
|
vector<string> &toremove) |
|
|
vector<string> &toremove) |
|
|
{ |
|
|
{ |
|
@ -188,14 +196,14 @@ _rename_preserve_path_one(Policy::Func::Search searchFunc, |
|
|
bool ismember; |
|
|
bool ismember; |
|
|
string newfullpath; |
|
|
string newfullpath; |
|
|
|
|
|
|
|
|
fs::path::make(oldbasepath,newfusepath,newfullpath); |
|
|
|
|
|
|
|
|
fs::path::make(&oldbasepath,newfusepath,newfullpath); |
|
|
|
|
|
|
|
|
ismember = member(oldbasepaths,oldbasepath); |
|
|
ismember = member(oldbasepaths,oldbasepath); |
|
|
if(ismember) |
|
|
if(ismember) |
|
|
{ |
|
|
{ |
|
|
string oldfullpath; |
|
|
string oldfullpath; |
|
|
|
|
|
|
|
|
fs::path::make(oldbasepath,oldfusepath,oldfullpath); |
|
|
|
|
|
|
|
|
fs::path::make(&oldbasepath,oldfusepath,oldfullpath); |
|
|
|
|
|
|
|
|
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); |
|
|
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); |
|
|
if((rv == -1) && (errno == ENOENT)) |
|
|
if((rv == -1) && (errno == ENOENT)) |
|
@ -224,13 +232,13 @@ _rename_preserve_path(Policy::Func::Search searchFunc, |
|
|
Policy::Func::Create createFunc, |
|
|
Policy::Func::Create createFunc, |
|
|
const vector<string> &srcmounts, |
|
|
const vector<string> &srcmounts, |
|
|
const size_t minfreespace, |
|
|
const size_t minfreespace, |
|
|
const string &oldfusepath, |
|
|
|
|
|
const string &newfusepath) |
|
|
|
|
|
|
|
|
const char *oldfusepath, |
|
|
|
|
|
const char *newfusepath) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
int error; |
|
|
int error; |
|
|
vector<string> toremove; |
|
|
vector<string> toremove; |
|
|
vector<string> oldbasepaths; |
|
|
|
|
|
|
|
|
vector<const string*> oldbasepaths; |
|
|
|
|
|
|
|
|
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); |
|
|
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
@ -241,7 +249,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc, |
|
|
{ |
|
|
{ |
|
|
const string &oldbasepath = srcmounts[i]; |
|
|
const string &oldbasepath = srcmounts[i]; |
|
|
|
|
|
|
|
|
_rename_preserve_path_one(searchFunc,createFunc, |
|
|
|
|
|
|
|
|
_rename_preserve_path_core(searchFunc,createFunc, |
|
|
srcmounts,minfreespace, |
|
|
srcmounts,minfreespace, |
|
|
oldbasepaths,oldbasepath, |
|
|
oldbasepaths,oldbasepath, |
|
|
oldfusepath,newfusepath, |
|
|
oldfusepath,newfusepath, |
|
|