Change getattr and statx to bespoke policies

* Provides: slight improvement in performance as it no longer will
need to find and then act on the files.
* It doesn't make sense to support all original policy types. Most
people used 'newest' or 'ff' and 'combine' is a better default which
has same runtime as 'newest' but with better output.
This commit is contained in:
Antonio SJ Musumeci 2025-11-13 20:45:52 -06:00
parent 965e26989c
commit b3b8e793f9
145 changed files with 3803 additions and 1192 deletions

View file

@ -18,75 +18,9 @@
#include "config.hpp"
#include "errno.hpp"
#include "fs_lremovexattr.hpp"
#include "fs_path.hpp"
#include "policy_rv.hpp"
#include "ugid.hpp"
#include "fuse.h"
#include <vector>
static
void
_removexattr_loop_core(const fs::path &basepath_,
const fs::path &fusepath_,
const char *attrname_,
PolicyRV *prv_)
{
fs::path fullpath;
fullpath = basepath_ / fusepath_;
errno = 0;
fs::lremovexattr(fullpath,attrname_);
prv_->insert(errno,basepath_);
}
static
void
_removexattr_loop(const std::vector<Branch*> &branches_,
const fs::path &fusepath_,
const char *attrname_,
PolicyRV *prv_)
{
for(auto &branch : branches_)
{
::_removexattr_loop_core(branch->path,fusepath_,attrname_,prv_);
}
}
static
int
_removexattr(const Policy::Action &actionFunc_,
const Policy::Search &searchFunc_,
const Branches &ibranches_,
const fs::path &fusepath_,
const char *attrname_)
{
int rv;
PolicyRV prv;
std::vector<Branch*> obranches;
rv = actionFunc_(ibranches_,fusepath_,obranches);
if(rv < 0)
return rv;
::_removexattr_loop(obranches,fusepath_,attrname_,&prv);
if(prv.errors.empty())
return 0;
if(prv.successes.empty())
return prv.errors[0].rv;
obranches.clear();
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv < 0)
return rv;
return prv.get_error(obranches[0]->path);
}
int
FUSE::removexattr(const fuse_req_ctx_t *ctx_,
@ -96,14 +30,12 @@ FUSE::removexattr(const fuse_req_ctx_t *ctx_,
const fs::path fusepath{fusepath_};
if(Config::is_ctrl_file(fusepath))
return -ENOATTR;
return -EROFS;
if(cfg.xattr.to_int())
return -cfg.xattr.to_int();
return ::_removexattr(cfg.func.removexattr.policy,
cfg.func.getxattr.policy,
cfg.branches,
fusepath,
attrname_);
return cfg.removexattr(cfg.branches,
fusepath,
attrname_);
}