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 4c5473d569
commit a61b587aed
32 changed files with 1050 additions and 239 deletions

View file

@ -34,42 +34,6 @@
#include <string>
static
void
_set_stat_if_leads_to_dir(const fs::path &path_,
struct stat *st_)
{
int rv;
struct stat st;
rv = fs::stat(path_,&st);
if(rv < 0)
return;
if(S_ISDIR(st.st_mode))
*st_ = st;
return;
}
static
void
_set_stat_if_leads_to_reg(const fs::path &path_,
struct stat *st_)
{
int rv;
struct stat st;
rv = fs::stat(path_,&st);
if(rv < 0)
return;
if(S_ISREG(st.st_mode))
*st_ = st;
return;
}
static
int
_getattr_fake_root(struct stat *st_)
@ -116,61 +80,6 @@ _getattr_controlfile(struct stat *st_)
return 0;
}
static
int
_getattr(const Policy::Search &searchFunc_,
const Branches &branches_,
const fs::path &fusepath_,
struct stat *st_,
const bool symlinkify_,
const time_t symlinkify_timeout_,
FollowSymlinks followsymlinks_)
{
int rv;
fs::path fullpath;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,branches);
if(rv < 0)
return rv;
fullpath = branches[0]->path / fusepath_;
switch(followsymlinks_)
{
case FollowSymlinks::ENUM::NEVER:
rv = fs::lstat(fullpath,st_);
break;
case FollowSymlinks::ENUM::DIRECTORY:
rv = fs::lstat(fullpath,st_);
if(S_ISLNK(st_->st_mode))
::_set_stat_if_leads_to_dir(fullpath,st_);
break;
case FollowSymlinks::ENUM::REGULAR:
rv = fs::lstat(fullpath,st_);
if(S_ISLNK(st_->st_mode))
::_set_stat_if_leads_to_reg(fullpath,st_);
break;
case FollowSymlinks::ENUM::ALL:
rv = fs::stat(fullpath,st_);
if(rv < 0)
rv = fs::lstat(fullpath,st_);
break;
}
if(rv < 0)
return rv;
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
symlinkify::convert(fullpath,st_);
fs::inode::calc(branches[0]->path,
fusepath_,
st_);
return 0;
}
int
_getattr(const fs::path &fusepath_,
struct stat *st_,
@ -178,13 +87,11 @@ _getattr(const fs::path &fusepath_,
{
int rv;
rv = ::_getattr(cfg.func.getattr.policy,
cfg.branches,
fusepath_,
st_,
cfg.symlinkify,
cfg.symlinkify_timeout,
cfg.follow_symlinks);
rv = cfg.getattr(cfg.branches,
fusepath_,
st_,
cfg.follow_symlinks,
cfg.symlinkify_timeout);
if((rv < 0) && Config::is_rootdir(fusepath_))
return ::_getattr_fake_root(st_);