diff --git a/src/fs.cpp b/src/fs.cpp index a852bfc0..4dc42cee 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -89,6 +89,17 @@ namespace fs return exists_on_rw_fs(path,st); } + bool + exists_on_rw_fs_with_at_least(const string &path, + const size_t minfreespace) + { + struct statvfs st; + + return (exists_on_rw_fs(path,st) + && + StatVFS::spaceavail(st) >= minfreespace); + } + void findallfiles(const vector &srcmounts, const char *fusepath, diff --git a/src/fs.hpp b/src/fs.hpp index f0622a77..364fa3ed 100644 --- a/src/fs.hpp +++ b/src/fs.hpp @@ -36,6 +36,9 @@ namespace fs struct statvfs &st); bool exists_on_rw_fs(const string &path); + bool exists_on_rw_fs_with_at_least(const string &path, + const size_t minfreespace); + void findallfiles(const vector &srcmounts, const char *fusepath, vector &paths); diff --git a/src/policy_all.cpp b/src/policy_all.cpp index decc8bdf..29a70088 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -29,27 +29,48 @@ using std::size_t; static int -_all(const vector &basepaths, +_all_create(const vector &srcmounts, + const size_t minfreespace, + vector &paths) +{ + for(size_t i = 0, ei = srcmounts.size(); i != ei; i++) + { + const string *basepath = &srcmounts[i]; + + if(!fs::exists_on_rw_fs_with_at_least(*basepath,minfreespace)) + continue; + + paths.push_back(basepath); + } + + if(paths.empty()) + return POLICY_FAIL_ENOENT; + + return POLICY_SUCCESS; +} + +static +int +_all(const vector &srcmounts, const char *fusepath, - const bool needswritablefs, vector &paths) { string fullpath; - for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + for(size_t i = 0, ei = srcmounts.size(); i != ei; i++) { - const string *basepath = &basepaths[i]; + const string *basepath = &srcmounts[i]; fs::path::make(basepath,fusepath,fullpath); - if(!fs::available(fullpath,needswritablefs)) + if(!fs::exists(fullpath)) continue; paths.push_back(basepath); } if(paths.empty()) - return (errno=ENOENT,POLICY_FAIL); + return POLICY_FAIL_ENOENT; return POLICY_SUCCESS; } @@ -58,16 +79,14 @@ namespace mergerfs { int Policy::Func::all(const Category::Enum::Type type, - const vector &basepaths, + const vector &srcmounts, const char *fusepath, const size_t minfreespace, vector &paths) { - const char *fp = - ((type == Category::Enum::create) ? "" : fusepath); - const bool needswritablefs = - (type == Category::Enum::create); + if(type == Category::Enum::create) + return _all_create(srcmounts,minfreespace,paths); - return _all(basepaths,fp,needswritablefs,paths); + return _all(srcmounts,fusepath,paths); } }