From cfe7609bcd480c06472dbe38a1fed25cece3d378 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 16 Aug 2014 13:59:55 -0400 Subject: [PATCH] find functions now return errors. closes #24 --- src/access.cpp | 6 ++--- src/chmod.cpp | 6 ++--- src/chown.cpp | 6 ++--- src/create.cpp | 13 +++++----- src/fs.cpp | 58 ++++++++++++++++++++++++++------------------- src/fs.hpp | 50 +++++++++++++++++++------------------- src/getattr.cpp | 6 ++--- src/getxattr.cpp | 6 ++--- src/link.cpp | 6 ++--- src/listxattr.cpp | 6 ++--- src/mkdir.cpp | 8 +++---- src/mknod.cpp | 6 ++--- src/open.cpp | 9 +++---- src/readlink.cpp | 6 ++--- src/removexattr.cpp | 6 ++--- src/rename.cpp | 6 ++--- src/rmdir.cpp | 6 ++--- src/setxattr.cpp | 6 ++--- src/truncate.cpp | 6 ++--- src/unlink.cpp | 6 ++--- src/utimens.cpp | 6 ++--- 21 files changed, 123 insertions(+), 111 deletions(-) diff --git a/src/access.cpp b/src/access.cpp index a727654c..67033bec 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -53,9 +53,9 @@ _access(const fs::SearchFunc searchFunc, int rv; fs::PathVector path; - searchFunc(srcmounts,fusepath,path); - if(path.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,path); + if(rv == -1) + return -errno; rv = ::eaccess(path[0].full.c_str(),mask); diff --git a/src/chmod.cpp b/src/chmod.cpp index e523aaf8..bd1f3466 100644 --- a/src/chmod.cpp +++ b/src/chmod.cpp @@ -48,9 +48,9 @@ _chmod(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/chown.cpp b/src/chown.cpp index 638c231b..a05ad0c3 100644 --- a/src/chown.cpp +++ b/src/chown.cpp @@ -50,9 +50,9 @@ _chown(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/create.cpp b/src/create.cpp index 9623ed4f..311389bd 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -54,19 +54,20 @@ _create(const fs::SearchFunc searchFunc, uint64_t &fh) { int fd; + int rv; string path; string dirname; fs::PathVector createpath; fs::PathVector existingpath; dirname = fs::dirname(fusepath); - searchFunc(srcmounts,dirname,existingpath); - if(existingpath.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,dirname,existingpath); + if(rv == -1) + return -errno; - createPathFunc(srcmounts,dirname,createpath); - if(createpath.empty()) - return -ENOSPC; + rv = createPathFunc(srcmounts,dirname,createpath); + if(rv == -1) + return -errno; if(createpath[0].base != existingpath[0].base) fs::clonepath(existingpath[0].base,createpath[0].base,dirname); diff --git a/src/fs.cpp b/src/fs.cpp index eb5bc038..17a81f17 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -490,19 +490,20 @@ namespace fs namespace find { - void + int invalid(const vector &basepaths, const string fusepath, PathVector &paths) { - return; + return (errno = EINVAL,-1); } - void + int ff(const vector &basepaths, const string fusepath, PathVector &paths) { + errno = ENOENT; for(vector::const_iterator iter = basepaths.begin(), eiter = basepaths.end(); iter != eiter; @@ -515,22 +516,20 @@ namespace fs path = fs::make_path(*iter,fusepath); rv = ::lstat(path.c_str(),&st); if(rv == 0) - { - paths.push_back(Path(*iter,path)); - return; - } + return (paths.push_back(Path(*iter,path)),0); } - return; + return -1; } - void + int ffwp(const vector &basepaths, const string fusepath, PathVector &paths) { Path fallback; + errno = ENOENT; for(vector::const_iterator iter = basepaths.begin(), eiter = basepaths.end(); iter != eiter; @@ -544,8 +543,7 @@ namespace fs rv = ::lstat(path.c_str(),&st); if(rv == 0) { - paths.push_back(Path(*iter,path)); - return; + return (paths.push_back(Path(*iter,path)),0); } else if(errno == EACCES) { @@ -555,12 +553,12 @@ namespace fs } if(!fallback.base.empty()) - paths.push_back(fallback); + return (paths.push_back(fallback),0); - return; + return -1; } - void + int newest(const vector &basepaths, const string fusepath, PathVector &paths) @@ -570,6 +568,7 @@ namespace fs vector::const_iterator niter; newest = 0; + errno = ENOENT; for(vector::const_iterator iter = basepaths.begin(), eiter = basepaths.end(); iter != eiter; @@ -589,16 +588,17 @@ namespace fs } if(newest) - paths.push_back(Path(*niter,npath)); + return (paths.push_back(Path(*niter,npath)),0); - return; + return -1; } - void + int all(const vector &basepaths, const string fusepath, PathVector &paths) { + errno = ENOENT; for(vector::const_iterator iter = basepaths.begin(), eiter = basepaths.end(); iter != eiter; @@ -614,18 +614,20 @@ namespace fs paths.push_back(Path(*iter,path)); } - return; + return paths.empty() ? -1 : 0; } - void + int mfs(const vector &basepaths, const string fusepath, PathVector &paths) { - fsblkcnt_t mfs = 0; + fsblkcnt_t mfs; string mfspath; string fullmfspath; + mfs = 0; + errno = ENOENT; for(vector::const_iterator iter = basepaths.begin(), eiter = basepaths.end(); iter != eiter; @@ -649,14 +651,17 @@ namespace fs } } + if(mfs == 0) + return -1; + fullmfspath = fs::make_path(mfspath,fusepath); paths.push_back(Path(mfspath,fullmfspath)); - return; + return 0; } - void + int epmfs(const vector &basepaths, const string fusepath, PathVector &paths) @@ -669,6 +674,9 @@ namespace fs vector::const_iterator iter = basepaths.begin(); vector::const_iterator eiter = basepaths.end(); + if(iter == eiter) + return (errno = ENOENT,-1); + do { int rv; @@ -709,10 +717,10 @@ namespace fs paths.push_back(Path(existingmfspath,path)); - return; + return 0; } - void + int rand(const vector &basepaths, const string fusepath, PathVector &paths) @@ -727,6 +735,8 @@ namespace fs fusepath); paths.push_back(Path(randombasepath,randomfullpath)); + + return 0; } } }; diff --git a/src/fs.hpp b/src/fs.hpp index 4dc4a6b3..113af2c2 100644 --- a/src/fs.hpp +++ b/src/fs.hpp @@ -49,7 +49,7 @@ namespace fs }; typedef vector PathVector; - typedef void (*SearchFunc)(const vector&,const string,PathVector&); + typedef int (*SearchFunc)(const vector&,const string,PathVector&); string dirname(const string path); string basename(const string path); @@ -112,30 +112,30 @@ namespace fs namespace find { - void invalid(const vector &basepaths, - const string fusepath, - PathVector &paths); - void ff(const vector &basepaths, - const string fusepath, - PathVector &paths); - void ffwp(const vector &paths, - const string fusepath, - PathVector &rv); - void newest(const vector &paths, - const string fusepath, - PathVector &rv); - void all(const vector &paths, - const string fusepath, - PathVector &rv); - void mfs(const vector &paths, - const string fusepath, - PathVector &rv); - void epmfs(const vector &paths, - const string fusepath, - PathVector &rv); - void rand(const vector &paths, - const string fusepath, - PathVector &rv); + int invalid(const vector &basepaths, + const string fusepath, + PathVector &paths); + int ff(const vector &basepaths, + const string fusepath, + PathVector &paths); + int ffwp(const vector &paths, + const string fusepath, + PathVector &rv); + int newest(const vector &paths, + const string fusepath, + PathVector &rv); + int all(const vector &paths, + const string fusepath, + PathVector &rv); + int mfs(const vector &paths, + const string fusepath, + PathVector &rv); + int epmfs(const vector &paths, + const string fusepath, + PathVector &rv); + int rand(const vector &paths, + const string fusepath, + PathVector &rv); } }; diff --git a/src/getattr.cpp b/src/getattr.cpp index 648f79c8..772f2884 100644 --- a/src/getattr.cpp +++ b/src/getattr.cpp @@ -73,9 +73,9 @@ _getattr(const fs::SearchFunc searchFunc, int rv; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = ::lstat(paths[0].full.c_str(),&buf); diff --git a/src/getxattr.cpp b/src/getxattr.cpp index ccaee00b..d58d83ef 100644 --- a/src/getxattr.cpp +++ b/src/getxattr.cpp @@ -109,9 +109,9 @@ _getxattr(const fs::SearchFunc searchFunc, int rv; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; if(!strcmp(attrname,"user.mergerfs.basepath")) rv = ::_getxattr_from_string(buf,count,paths[0].base); diff --git a/src/link.cpp b/src/link.cpp index d41c963b..275b7a5f 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -50,9 +50,9 @@ _link(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,from,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,from,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/listxattr.cpp b/src/listxattr.cpp index 463c8f27..ad25ccfd 100644 --- a/src/listxattr.cpp +++ b/src/listxattr.cpp @@ -77,9 +77,9 @@ _listxattr(const fs::SearchFunc searchFunc, int rv; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = ::llistxattr(paths[0].full.c_str(),list,size); diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 065b9e00..34217737 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -58,11 +58,11 @@ _mkdir(const fs::SearchFunc searchFunc, return -EEXIST; dirname = fs::dirname(fusepath); - searchFunc(srcmounts,dirname,existingpath); - if(existingpath.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,dirname,existingpath); + if(rv == -1) + return -errno; - createPathFunc(srcmounts,dirname,createpath); + rv = createPathFunc(srcmounts,dirname,createpath); if(createpath[0].base != existingpath[0].base) fs::clonepath(existingpath[0].base,createpath[0].base,dirname); diff --git a/src/mknod.cpp b/src/mknod.cpp index ccca0ba2..a6b16118 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -60,9 +60,9 @@ _mknod(const fs::SearchFunc searchFunc, return -EEXIST; dirname = fs::dirname(fusepath); - searchFunc(srcmounts,dirname,existingpath); - if(existingpath.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,dirname,existingpath); + if(rv == -1) + return -errno; createPathFunc(srcmounts,dirname,createpath); if(existingpath[0].base != createpath[0].base) diff --git a/src/open.cpp b/src/open.cpp index 3bd4ec92..5ac24581 100644 --- a/src/open.cpp +++ b/src/open.cpp @@ -49,12 +49,13 @@ _open(const fs::SearchFunc searchFunc, const int flags, uint64_t &fh) { - int fd; + int fd; + int rv; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; fd = ::open(paths[0].full.c_str(),flags); if(fd == -1) diff --git a/src/readlink.cpp b/src/readlink.cpp index cfc1d646..9a430bd8 100644 --- a/src/readlink.cpp +++ b/src/readlink.cpp @@ -50,9 +50,9 @@ _readlink(const fs::SearchFunc searchFunc, int rv; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = ::readlink(paths[0].full.c_str(),buf,size); if(rv == -1) diff --git a/src/removexattr.cpp b/src/removexattr.cpp index b5d3ce40..f62ac2c1 100644 --- a/src/removexattr.cpp +++ b/src/removexattr.cpp @@ -51,9 +51,9 @@ _removexattr(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/rename.cpp b/src/rename.cpp index a8aaee4d..84339b5b 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -50,9 +50,9 @@ _rename(const fs::SearchFunc searchFunc, string pathto; fs::PathVector pathfrom; - searchFunc(srcmounts,from,pathfrom); - if(pathfrom.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,from,pathfrom); + if(rv == -1) + return -errno; pathto = fs::make_path(pathfrom[0].base,to); diff --git a/src/rmdir.cpp b/src/rmdir.cpp index dff8603f..92834cbe 100644 --- a/src/rmdir.cpp +++ b/src/rmdir.cpp @@ -48,9 +48,9 @@ _rmdir(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/setxattr.cpp b/src/setxattr.cpp index 04a63edf..dc257779 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -235,9 +235,9 @@ _setxattr(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/truncate.cpp b/src/truncate.cpp index da5a297a..501b612c 100644 --- a/src/truncate.cpp +++ b/src/truncate.cpp @@ -50,9 +50,9 @@ _truncate(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/unlink.cpp b/src/unlink.cpp index da7460c5..f9900c4a 100644 --- a/src/unlink.cpp +++ b/src/unlink.cpp @@ -48,9 +48,9 @@ _unlink(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0; diff --git a/src/utimens.cpp b/src/utimens.cpp index 356b5f20..7a75ee92 100644 --- a/src/utimens.cpp +++ b/src/utimens.cpp @@ -50,9 +50,9 @@ _utimens(const fs::SearchFunc searchFunc, int error; fs::PathVector paths; - searchFunc(srcmounts,fusepath,paths); - if(paths.empty()) - return -ENOENT; + rv = searchFunc(srcmounts,fusepath,paths); + if(rv == -1) + return -errno; rv = -1; error = 0;