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
|
|
@ -27,39 +27,17 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
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
|
||||
chmod_loop_core(const string &basepath_,
|
||||
const char *fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
chmod_loop_core(const std::string &basepath_,
|
||||
const char *fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
string fullpath;
|
||||
std::string fullpath;
|
||||
|
||||
fullpath = fs::path::make(basepath_,fusepath_);
|
||||
|
||||
|
|
@ -71,14 +49,14 @@ namespace l
|
|||
|
||||
static
|
||||
void
|
||||
chmod_loop(const StrVec &basepaths_,
|
||||
const char *fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
chmod_loop(const std::vector<Branch*> &branches_,
|
||||
const char *fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
|
||||
for(auto &branch : branches_)
|
||||
{
|
||||
l::chmod_loop_core(basepaths_[i],fusepath_,mode_,prv_);
|
||||
l::chmod_loop_core(branch->path,fusepath_,mode_,prv_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,24 +70,24 @@ namespace l
|
|||
{
|
||||
int rv;
|
||||
PolicyRV prv;
|
||||
StrVec basepaths;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = actionFunc_(branches_,fusepath_,&basepaths);
|
||||
rv = actionFunc_(branches_,fusepath_,branches);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
l::chmod_loop(basepaths,fusepath_,mode_,&prv);
|
||||
if(prv.error.empty())
|
||||
l::chmod_loop(branches,fusepath_,mode_,&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