diff --git a/include/common/metadata.hpp b/include/common/metadata.hpp index d64f94921439be0d738c6dda01b7059f94457dbf..9121f10c5a9cc04145a43286b952adf4f0b0cdf7 100644 --- a/include/common/metadata.hpp +++ b/include/common/metadata.hpp @@ -64,6 +64,8 @@ private: #endif #endif + void + init_time(); public: Metadata() = default; @@ -82,11 +84,12 @@ public: std::string serialize() const; + // currently unused void - init_ACM_time(); + update_atime_now(); void - update_ACM_time(bool a, bool c, bool m); + update_mtime_now(); // Getter and Setter time_t diff --git a/src/common/metadata.cpp b/src/common/metadata.cpp index 26f60ced5bcfeb52b9c381b5f27222f0a8b3dcfb..dc725f7a8be2ba5d210d1363042fe43a9cc4511a 100644 --- a/src/common/metadata.cpp +++ b/src/common/metadata.cpp @@ -69,22 +69,36 @@ gen_unique_id(const std::string& path) { return static_cast(hash_value & 0xFFFF); } +inline void +Metadata::init_time() { + if constexpr(gkfs::config::metadata::use_ctime) { + ctime_ = std::time(nullptr); + } + if constexpr(gkfs::config::metadata::use_mtime) { + mtime_ = std::time(nullptr); + } + if constexpr(gkfs::config::metadata::use_atime) { + atime_ = std::time(nullptr); + } +} + Metadata::Metadata(const mode_t mode) - : atime_(), mtime_(), ctime_(), mode_(mode), link_count_(0), size_(0), - blocks_(0) { + : mode_(mode), link_count_(0), size_(0), blocks_(0) { assert(S_ISDIR(mode_) || S_ISREG(mode_)); + init_time(); } #ifdef HAS_SYMLINKS Metadata::Metadata(const mode_t mode, const std::string& target_path) - : atime_(), mtime_(), ctime_(), mode_(mode), link_count_(0), size_(0), - blocks_(0), target_path_(target_path) { + : mode_(mode), link_count_(0), size_(0), blocks_(0), + target_path_(target_path) { assert(S_ISLNK(mode_) || S_ISDIR(mode_) || S_ISREG(mode_)); // target_path should be there only if this is a link assert(target_path_.empty() || S_ISLNK(mode_)); // target_path should be absolute assert(target_path_.empty() || target_path_[0] == '/'); + init_time(); } #endif @@ -205,24 +219,15 @@ Metadata::serialize() const { } void -Metadata::init_ACM_time() { - std::time_t time; - std::time(&time); +Metadata::update_atime_now() { + auto time = std::time(nullptr); atime_ = time; - mtime_ = time; - ctime_ = time; } void -Metadata::update_ACM_time(bool a, bool c, bool m) { - std::time_t time; - std::time(&time); - if(a) - atime_ = time; - if(c) - ctime_ = time; - if(m) - mtime_ = time; +Metadata::update_mtime_now() { + auto time = std::time(nullptr); + mtime_ = time; } //-------------------------------------------- GETTER/SETTER diff --git a/src/daemon/backend/metadata/merge.cpp b/src/daemon/backend/metadata/merge.cpp index 4f5d134ef09ba02c202b214cf8d0fa1eb2831a8a..67cd80cd9979348a17be093225b7c98064ff4a8f 100644 --- a/src/daemon/backend/metadata/merge.cpp +++ b/src/daemon/backend/metadata/merge.cpp @@ -181,6 +181,10 @@ MetadataMergeOperator::FullMergeV2(const MergeOperationInput& merge_in, auto operand_id = MergeOperand::get_id(serialized_op); auto parameters = MergeOperand::get_params(serialized_op); + if constexpr(gkfs::config::metadata::use_mtime) { + md.update_mtime_now(); + } + if(operand_id == OperandID::increase_size) { auto op = IncreaseSizeOperand(parameters); if(op.append()) { diff --git a/src/daemon/ops/metadentry.cpp b/src/daemon/ops/metadentry.cpp index c456ed4a910ec28fabf089ac1be751c0011c99fc..17f470fc1c92c44c142f6b78db3a7c7609b4eb1b 100644 --- a/src/daemon/ops/metadentry.cpp +++ b/src/daemon/ops/metadentry.cpp @@ -76,7 +76,7 @@ create(const std::string& path, Metadata& md) { if(GKFS_DATA->ctime_state()) md.ctime(time); } - if(gkfs::config::metadata::create_exist_check) { + if constexpr(gkfs::config::metadata::create_exist_check) { GKFS_DATA->mdb()->put_no_exist(path, md.serialize()); } else { GKFS_DATA->mdb()->put(path, md.serialize()); diff --git a/tests/integration/status/test_status.py b/tests/integration/status/test_status.py index df75b855f815a85cbaefe6b70cdcf84a261188d5..96dd43c22ecdcfaacf565d1b164eeb2014087c36 100644 --- a/tests/integration/status/test_status.py +++ b/tests/integration/status/test_status.py @@ -36,6 +36,7 @@ import sh import sys import pytest from harness.logger import logger +from datetime import datetime nonexisting = "nonexisting" @@ -52,6 +53,11 @@ def test_statx(gkfs_daemon, gkfs_client): file_a = topdir / "file_a" subdir_a = dir_a / "subdir_a" + # creation timestamp + # it is only checked if mtime and ctime are greater than + # the creation timestamp due to inprecesion between test and daemon + ts = int(datetime.timestamp(datetime.now())) + # create topdir ret = gkfs_client.mkdir( topdir, @@ -91,6 +97,13 @@ def test_statx(gkfs_daemon, gkfs_client): assert ret.retval == 0 assert (ret.statbuf.stx_size == 2) + # if greater zero, it is activated in config.hpp + if ret.statbuf.stx_mtime.tv_sec > 0: + assert (ret.statbuf.stx_mtime.tv_sec > ts) + + if ret.statbuf.stx_ctime.tv_sec > 0: + assert (ret.statbuf.stx_ctime.tv_sec > ts) + return