diff --git a/src/CryFuse.cpp b/src/CryFuse.cpp index 3cb8e2f3..706e8745 100644 --- a/src/CryFuse.cpp +++ b/src/CryFuse.cpp @@ -180,17 +180,13 @@ int CryFuse::ftruncate(const path &path, off_t size, fuse_file_info *fileinfo) { //TODO int CryFuse::utimens(const path &path, const timespec times[2]) { - UNUSED(times); - printf("NOT IMPLEMENTED: utimens(%s, _)\n", path.c_str()); - //auto real_path = _device->RootDir() / path; - //struct timeval tv[2]; - //tv[0].tv_sec = times[0].tv_sec; - //tv[0].tv_usec = times[0].tv_nsec / 1000; - //tv[1].tv_sec = times[1].tv_sec; - //tv[1].tv_usec = times[1].tv_nsec / 1000; - //int retstat = ::lutimes(real_path.c_str(), tv); - //return errcode_map(retstat); - return 0; + //printf("utimens(%s, _)\n", path.c_str()); + try { + _device->utimens(path, times); + return 0; + } catch (CryErrnoException &e) { + return -e.getErrno(); + } } int CryFuse::open(const path &path, fuse_file_info *fileinfo) { diff --git a/src/cryfs_lib/CryDevice.cpp b/src/cryfs_lib/CryDevice.cpp index 4e5cc653..b821c89e 100644 --- a/src/cryfs_lib/CryDevice.cpp +++ b/src/cryfs_lib/CryDevice.cpp @@ -144,3 +144,7 @@ void CryDevice::closeDir(int descriptor) { _open_dirs.close(descriptor); } +void CryDevice::utimens(const bf::path &path, const timespec times[2]) { + auto node = Load(path); + node->utimens(times); +} diff --git a/src/cryfs_lib/CryDevice.h b/src/cryfs_lib/CryDevice.h index 12744f91..df9627c9 100644 --- a/src/cryfs_lib/CryDevice.h +++ b/src/cryfs_lib/CryDevice.h @@ -39,10 +39,10 @@ public: void rmdir(const bf::path &path); void unlink(const bf::path &path); void rename(const bf::path &from, const bf::path &to); - int openDir(const bf::path &path); std::unique_ptr> readDir(int descriptor); void closeDir(int descriptor); + void utimens(const bf::path &path, const timespec times[2]); const bf::path &RootDir() const; private: diff --git a/src/cryfs_lib/CryNode.cpp b/src/cryfs_lib/CryNode.cpp index 3b4bd836..7718ee7a 100644 --- a/src/cryfs_lib/CryNode.cpp +++ b/src/cryfs_lib/CryNode.cpp @@ -1,5 +1,7 @@ #include "CryNode.h" +#include + #include "CryDevice.h" #include "CryErrnoException.h" @@ -29,4 +31,11 @@ void CryNode::rename(const bf::path &to) { _path = to; } +void CryNode::utimens(const timespec times[2]) { + struct timeval timevals[2]; + TIMESPEC_TO_TIMEVAL(&timevals[0], ×[0]); + TIMESPEC_TO_TIMEVAL(&timevals[1], ×[1]); + ::lutimes(base_path().c_str(), timevals); +} + } /* namespace cryfs */ diff --git a/src/cryfs_lib/CryNode.h b/src/cryfs_lib/CryNode.h index de694b0e..3499d038 100644 --- a/src/cryfs_lib/CryNode.h +++ b/src/cryfs_lib/CryNode.h @@ -20,6 +20,7 @@ public: void stat(struct ::stat *result) const; void access(int mask) const; void rename(const bf::path &to); + void utimens(const timespec times[2]); protected: bf::path base_path() const;