Commit c4d2a5a0 authored by Marc Vef's avatar Marc Vef
Browse files

Merge branch 'jathenst/225-support-mtime' into 'master'

Resolve "Support mtime"

Closes #225

Closes #225

See merge request !178
parents f8128050 6c68de44
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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
+23 −18
Original line number Diff line number Diff line
@@ -69,22 +69,36 @@ gen_unique_id(const std::string& path) {
    return static_cast<uint16_t>(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,23 +219,14 @@ 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)
Metadata::update_mtime_now() {
    auto time = std::time(nullptr);
    mtime_ = time;
}

+4 −0
Original line number Diff line number Diff line
@@ -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()) {
+1 −1
Original line number Diff line number Diff line
@@ -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());
+13 −0
Original line number Diff line number Diff line
@@ -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