mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Rework policies to return branches rather than path strings
This commit is contained in:
parent
7e084ea7db
commit
86b50d2d4e
86 changed files with 1259 additions and 3088 deletions
|
|
@ -26,41 +26,18 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
int
|
||||
get_error(const PolicyRV &prv_,
|
||||
const string &basepath_)
|
||||
{
|
||||
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
|
||||
{
|
||||
if(prv_.success[i].basepath == basepath_)
|
||||
return prv_.success[i].rv;
|
||||
}
|
||||
|
||||
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
|
||||
{
|
||||
if(prv_.error[i].basepath == basepath_)
|
||||
return prv_.error[i].rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
chown_loop_core(const string &basepath_,
|
||||
const char *fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
chown_loop_core(const std::string &basepath_,
|
||||
const char *fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
string fullpath;
|
||||
std::string fullpath;
|
||||
|
||||
fullpath = fs::path::make(basepath_,fusepath_);
|
||||
|
||||
|
|
@ -72,15 +49,15 @@ namespace l
|
|||
|
||||
static
|
||||
void
|
||||
chown_loop(const vector<string> &basepaths_,
|
||||
const char *fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
chown_loop(const std::vector<Branch*> &branches_,
|
||||
const char *fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
|
||||
for(auto &branch : branches_)
|
||||
{
|
||||
l::chown_loop_core(basepaths_[i],fusepath_,uid_,gid_,prv_);
|
||||
l::chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,24 +72,24 @@ namespace l
|
|||
{
|
||||
int rv;
|
||||
PolicyRV prv;
|
||||
vector<string> basepaths;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = actionFunc_(branches_,fusepath_,&basepaths);
|
||||
rv = actionFunc_(branches_,fusepath_,branches);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
l::chown_loop(basepaths,fusepath_,uid_,gid_,&prv);
|
||||
if(prv.error.empty())
|
||||
l::chown_loop(branches,fusepath_,uid_,gid_,&prv);
|
||||
if(prv.errors.empty())
|
||||
return 0;
|
||||
if(prv.success.empty())
|
||||
return prv.error[0].rv;
|
||||
if(prv.successes.empty())
|
||||
return prv.errors[0].rv;
|
||||
|
||||
basepaths.clear();
|
||||
rv = searchFunc_(branches_,fusepath_,&basepaths);
|
||||
branches.clear();
|
||||
rv = searchFunc_(branches_,fusepath_,branches);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return l::get_error(prv,basepaths[0]);
|
||||
return prv.get_error(branches[0]->path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue