Browse Source

Merge pull request #238 from trapexit/policy-all

add readonly and minfreespace filters to all policy for creates. clos…
pull/240/head
Antonio SJ Musumeci 9 years ago
parent
commit
98a051b161
  1. 11
      src/fs.cpp
  2. 3
      src/fs.hpp
  3. 43
      src/policy_all.cpp

11
src/fs.cpp

@ -89,6 +89,17 @@ namespace fs
return exists_on_rw_fs(path,st); 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 void
findallfiles(const vector<string> &srcmounts, findallfiles(const vector<string> &srcmounts,
const char *fusepath, const char *fusepath,

3
src/fs.hpp

@ -36,6 +36,9 @@ namespace fs
struct statvfs &st); struct statvfs &st);
bool exists_on_rw_fs(const string &path); 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<string> &srcmounts, void findallfiles(const vector<string> &srcmounts,
const char *fusepath, const char *fusepath,
vector<string> &paths); vector<string> &paths);

43
src/policy_all.cpp

@ -29,27 +29,48 @@ using std::size_t;
static static
int int
_all(const vector<string> &basepaths,
_all_create(const vector<string> &srcmounts,
const size_t minfreespace,
vector<const string*> &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<string> &srcmounts,
const char *fusepath, const char *fusepath,
const bool needswritablefs,
vector<const string*> &paths) vector<const string*> &paths)
{ {
string fullpath; 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); fs::path::make(basepath,fusepath,fullpath);
if(!fs::available(fullpath,needswritablefs))
if(!fs::exists(fullpath))
continue; continue;
paths.push_back(basepath); paths.push_back(basepath);
} }
if(paths.empty()) if(paths.empty())
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
return POLICY_SUCCESS; return POLICY_SUCCESS;
} }
@ -58,16 +79,14 @@ namespace mergerfs
{ {
int int
Policy::Func::all(const Category::Enum::Type type, Policy::Func::all(const Category::Enum::Type type,
const vector<string> &basepaths,
const vector<string> &srcmounts,
const char *fusepath, const char *fusepath,
const size_t minfreespace, const size_t minfreespace,
vector<const string*> &paths) vector<const string*> &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);
} }
} }
Loading…
Cancel
Save