From 52e6a43808e776d120eba9b9c3837e6fc179f800 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 26 Nov 2024 01:19:11 -0600 Subject: [PATCH] timespec_utils.hpp --- src/func_getattr_newest.cpp | 47 +++++++++++++++++++++++++++++++++++++ src/func_getattr_newest.hpp | 17 ++++++++++++++ src/timespec_utils.hpp | 6 ++--- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/func_getattr_newest.cpp create mode 100644 src/func_getattr_newest.hpp diff --git a/src/func_getattr_newest.cpp b/src/func_getattr_newest.cpp new file mode 100644 index 00000000..8da53ffc --- /dev/null +++ b/src/func_getattr_newest.cpp @@ -0,0 +1,47 @@ +#include "func_getattr_newest.hpp" + +#include "fs_lstat.hpp" +#include "fs_inode.hpp" +#include "timespec_utils.hpp" + +int +Func2::GetattrNewest::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_newest.hpp b/src/func_getattr_newest.hpp new file mode 100644 index 00000000..1bf52a63 --- /dev/null +++ b/src/func_getattr_newest.hpp @@ -0,0 +1,17 @@ +#include "func_getattr_base.hpp" + +namespace Func2 +{ + class GetattrNewest : public GetattrBase + { + public: + GetattrNewest() {} + ~GetattrNewest() {} + + 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 index 96673afc..1095f34c 100644 --- a/src/timespec_utils.hpp +++ b/src/timespec_utils.hpp @@ -9,14 +9,14 @@ namespace TimeSpec const timespec &t1_) { if(t0_.tv_sec > t1_.tv_sec) - return t0_; + return true; if(t0_.tv_sec == t1_.tv_sec) { if(t0_.tv_nsec > t1_.tv_nsec) - return t0_; + return true; } - return t1_; + return false; } static