diff --git a/src/func_getattr_combine.cpp b/src/func_getattr_combine.cpp new file mode 100644 index 00000000..d977038a --- /dev/null +++ b/src/func_getattr_combine.cpp @@ -0,0 +1,47 @@ +#include "func_getattr_combine.hpp" + +#include "fs_lstat.hpp" +#include "fs_inode.hpp" +#include "timespec_utils.hpp" + +int +Func2::GetattrCombine::process(const Branches &branches_, + const fs::Path &fusepath_, + struct stat *st_, + fuse_timeouts_t *timeout_) +{ + int rv; + Branches::CPtr branches; + fs::Path fullpath; + + branches = branches_; + + for(const auto &branch : *branches) + { + struct stat st; + + fullpath = branch.path; + fullpath += fusepath_; + rv = fs::lstat(fullpath.c_str(),&st); + if(rv == -1) + continue; + + if(st_->st_ino == 0) + { + *st_ = st; + continue; + } + + st_->st_atim = TimeSpec::newest(st_->st_atim,st.st_atim); + st_->st_ctim = TimeSpec::newest(st_->st_ctim,st.st_ctim); + st_->st_mtim = TimeSpec::newest(st_->st_mtim,st.st_mtim); + st_->st_nlink += st.st_nlink; + } + + if(st_->st_ino == 0) + return -ENOENT; + + fs::inode::calc(fusepath_,st_); + + return 0; +} diff --git a/src/func_getattr_combine.hpp b/src/func_getattr_combine.hpp new file mode 100644 index 00000000..f0dd89a0 --- /dev/null +++ b/src/func_getattr_combine.hpp @@ -0,0 +1,17 @@ +#include "func_getattr_base.hpp" + +namespace Func2 +{ + class GetattrCombine : public GetattrBase + { + public: + GetattrCombine() {} + ~GetattrCombine() {} + + public: + int process(const Branches &branches, + const fs::Path &fusepath, + struct stat *st, + fuse_timeouts_t *timeout); + }; +} diff --git a/src/timespec_utils.hpp b/src/timespec_utils.hpp new file mode 100644 index 00000000..8a8f721a --- /dev/null +++ b/src/timespec_utils.hpp @@ -0,0 +1,21 @@ +#pragma once + +namespace TimeSpec +{ + static + inline + timespec + newest(const timespec &t0_, + const timespec &t1_) + { + if(t0_.tv_sec > t1_.tv_sec) + return t0_; + if(t0_.tv_sec == t1_.tv_sec) + { + if(t0_.tv_nsec > t1_.tv_nsec) + return t0_; + } + + return t1_; + } +}