From 35075bb0cd7e883ced9b343d403ae7905344702c Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 6 Dec 2016 16:48:52 -0500 Subject: [PATCH] return clonepath errors currently the error is ignored and it was expected the primary call would fail. problem is it returns confusing errors as a result. (eg ENOENT vs EPERM) --- src/create.cpp | 12 +++++++----- src/link.cpp | 33 ++++++++++++++------------------- src/mkdir.cpp | 4 +++- src/mknod.cpp | 4 +++- src/rename.cpp | 30 +++++++++++++++++++++++------- src/symlink.cpp | 4 +++- 6 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/create.cpp b/src/create.cpp index b96a087a..76586a53 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -43,22 +43,24 @@ _create_core(const string &existingpath, const int flags, uint64_t &fh) { - int fd; + int rv; string fullpath; if(createpath != existingpath) { const ugid::SetRootGuard ugidGuard; - fs::clonepath(existingpath,createpath,fusedirpath); + rv = fs::clonepath(existingpath,createpath,fusedirpath); + if(rv == -1) + return -errno; } fs::path::make(&createpath,fusepath,fullpath); - fd = fs::open(fullpath,flags,mode); - if(fd == -1) + rv = fs::open(fullpath,flags,mode); + if(rv == -1) return -errno; - fh = reinterpret_cast(new FileInfo(fd)); + fh = reinterpret_cast(new FileInfo(rv)); return 0; } diff --git a/src/link.cpp b/src/link.cpp index 00e2bf2c..bae5232e 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -49,7 +49,9 @@ _link_create_path_core(const string &oldbasepath, if(oldbasepath != newbasepath) { const ugid::SetRootGuard ugidGuard; - fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); + rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); + if(rv == -1) + return errno; } fs::path::make(&oldbasepath,oldfusepath,oldfullpath); @@ -131,25 +133,18 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc, newfusedirpathcstr = newfusedirpath.c_str(); rv = createFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath); - if(rv != -1) - { - if(oldbasepath == *newbasepath[0]) - { - rv = searchFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath); - if(rv != -1) - { - const ugid::SetRootGuard ugidGuard; - fs::clonepath(*newbasepath[0],oldbasepath,newfusedirpathcstr); - } - } - else - { - rv = -1; - errno = EXDEV; - } - } + if(rv == -1) + return -1; + + if(oldbasepath != *newbasepath[0]) + return (errno=EXDEV,-1); + + rv = searchFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath); + if(rv == -1) + return -1; - return rv; + const ugid::SetRootGuard ugidGuard; + return fs::clonepath(*newbasepath[0],oldbasepath,newfusedirpathcstr); } static diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 6d7efecc..83b38081 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -48,7 +48,9 @@ _mkdir_loop_core(const string &existingpath, if(createpath != existingpath) { const ugid::SetRootGuard ugidGuard; - fs::clonepath(existingpath,createpath,fusedirpath); + rv = fs::clonepath(existingpath,createpath,fusedirpath); + if(rv == -1) + return errno; } fs::path::make(&createpath,fusepath,fullpath); diff --git a/src/mknod.cpp b/src/mknod.cpp index 164e9d61..4b31954a 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -48,7 +48,9 @@ _mknod_loop_core(const string &existingpath, if(createpath != existingpath) { const ugid::SetRootGuard ugidGuard; - fs::clonepath(existingpath,createpath,fusedirpath); + rv = fs::clonepath(existingpath,createpath,fusedirpath); + if(rv == -1) + return -1; } fs::path::make(&createpath,fusepath,fullpath); diff --git a/src/rename.cpp b/src/rename.cpp index bb3cfcd1..41cc3c0e 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -57,6 +57,27 @@ _remove(const vector &toremove) ::remove(toremove[i].c_str()); } +static +int +_rename(const std::string &oldbasepath, + const std::string &oldfullpath, + const std::string &newbasepath, + const std::string &newfusedirpath, + const std::string &newfullpath) +{ + int rv; + + if(oldbasepath != newbasepath) + { + const ugid::SetRootGuard guard; + rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); + if(rv == -1) + return -1; + } + + return fs::rename(oldfullpath,newfullpath); +} + static void _rename_create_path_core(const vector &oldbasepaths, @@ -78,15 +99,10 @@ _rename_create_path_core(const vector &oldbasepaths, ismember = member(oldbasepaths,oldbasepath); if(ismember) { - if(oldbasepath != newbasepath) - { - const ugid::SetRootGuard ugidGuard; - fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); - } - fs::path::make(&oldbasepath,oldfusepath,oldfullpath); - rv = fs::rename(oldfullpath,newfullpath); + rv = _rename(oldbasepath,oldfullpath, + newbasepath,newfusedirpath,newfullpath); error = calc_error(rv,error,errno); if(RENAME_FAILED(rv)) tounlink.push_back(oldfullpath); diff --git a/src/symlink.cpp b/src/symlink.cpp index e76e210f..8ec2a5b9 100644 --- a/src/symlink.cpp +++ b/src/symlink.cpp @@ -49,7 +49,9 @@ _symlink_loop_core(const string &existingpath, if(newbasepath != existingpath) { const ugid::SetRootGuard ugidGuard; - fs::clonepath(existingpath,newbasepath,newdirpath); + rv = fs::clonepath(existingpath,newbasepath,newdirpath); + if(rv == -1) + return -1; } fs::path::make(&newbasepath,newpath,fullnewpath);