Skip to content

Commit

Permalink
Merge pull request #1231 from trapexit/readdir
Browse files Browse the repository at this point in the history
Fix setting of ugids for concurrent readdir
  • Loading branch information
trapexit authored Aug 21, 2023
2 parents e0087cd + e586d2f commit 3a1d8e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
25 changes: 18 additions & 7 deletions src/fuse_readdir_cor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ namespace l
concurrent_readdir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
fuse_dirents_t *buf_,
uid_t const uid_,
gid_t const gid_)
{
HashSet names;
std::mutex names_mutex;
Expand All @@ -130,9 +132,12 @@ namespace l

for(auto const &branch : *branches_)
{
auto func = [&]()
auto func = [&,dirname_,buf_,uid_,gid_]()
{
std::string basepath = fs::path::make(branch.path,dirname_);
std::string basepath;
ugid::Set const ugid(uid_,gid_);

basepath = fs::path::make(branch.path,dirname_);

return l::readdir(basepath,names,names_mutex,buf_,dirents_mutex);
};
Expand Down Expand Up @@ -169,13 +174,15 @@ namespace l
readdir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
fuse_dirents_t *buf_,
uid_t const uid_,
gid_t const gid_)
{
std::vector<int> rvs;

fuse_dirents_reset(buf_);

rvs = l::concurrent_readdir(tp_,branches_,dirname_,buf_);
rvs = l::concurrent_readdir(tp_,branches_,dirname_,buf_,uid_,gid_);

return l::calc_rv(rvs);
}
Expand All @@ -188,7 +195,11 @@ FUSE::ReadDirCOR::operator()(fuse_file_info_t const *ffi_,
Config::Read cfg;
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh);
const fuse_context *fc = fuse_get_context();
const ugid::Set ugid(fc->uid,fc->gid);

return l::readdir(_tp,cfg->branches,di->fusepath.c_str(),buf_);
return l::readdir(_tp,
cfg->branches,
di->fusepath.c_str(),
buf_,
fc->uid,
fc->gid);
}
25 changes: 18 additions & 7 deletions src/fuse_readdir_cosr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,20 @@ namespace l
std::vector<std::future<DIR*>>
opendir(ThreadPool &tp_,
const Branches::CPtr &branches_,
char const *dirname_)
char const *dirname_,
uid_t const uid_,
gid_t const gid_)
{
std::vector<std::future<DIR*>> futures;

for(auto const &branch : *branches_)
{
auto func = [&branch,dirname_]()
auto func = [&branch,dirname_,uid_,gid_]()
{
std::string basepath = fs::path::make(branch.path,dirname_);
std::string basepath;
ugid::Set const ugid(uid_,gid_);

basepath = fs::path::make(branch.path,dirname_);

return fs::opendir(basepath);
};
Expand Down Expand Up @@ -146,14 +151,16 @@ namespace l
readdir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
fuse_dirents_t *buf_,
uid_t const uid_,
gid_t const gid_)
{
int rv;
std::vector<std::future<DIR*>> dh_futures;

fuse_dirents_reset(buf_);

dh_futures = l::opendir(tp_,branches_,dirname_);
dh_futures = l::opendir(tp_,branches_,dirname_,uid_,gid_);
rv = l::readdir(dh_futures,dirname_,buf_);

return rv;
Expand All @@ -167,7 +174,11 @@ FUSE::ReadDirCOSR::operator()(fuse_file_info_t const *ffi_,
Config::Read cfg;
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh);
const fuse_context *fc = fuse_get_context();
const ugid::Set ugid(fc->uid,fc->gid);

return l::readdir(_tp,cfg->branches,di->fusepath.c_str(),buf_);
return l::readdir(_tp,
cfg->branches,
di->fusepath.c_str(),
buf_,
fc->uid,
fc->gid);
}
4 changes: 3 additions & 1 deletion src/fuse_readdir_seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@ FUSE::ReadDirSeq::operator()(fuse_file_info_t const *ffi_,
const fuse_context *fc = fuse_get_context();
const ugid::Set ugid(fc->uid,fc->gid);

return l::readdir(cfg->branches,di->fusepath.c_str(),buf_);
return l::readdir(cfg->branches,
di->fusepath.c_str(),
buf_);
}

0 comments on commit 3a1d8e0

Please sign in to comment.