diff --git a/src/cpp-utils/system/stat.h b/src/cpp-utils/system/stat.h new file mode 100644 index 00000000..f6fb2660 --- /dev/null +++ b/src/cpp-utils/system/stat.h @@ -0,0 +1,14 @@ +#pragma once +#ifndef MESSMER_CPPUTILS_SYSTEM_STAT_H +#define MESSMER_CPPUTILS_SYSTEM_STAT_H + +/** + * For platform independence: Apple doesn't have stat.st_atim, but stat.st_atimespec + */ +#ifdef __APPLE__ +# define st_atim st_atimespec +# define st_mtim st_mtimespec +# define st_ctim st_ctimespec +#endif + +#endif diff --git a/src/cryfs/filesystem/CryNode.cpp b/src/cryfs/filesystem/CryNode.cpp index 597f8a67..5bb123ed 100644 --- a/src/cryfs/filesystem/CryNode.cpp +++ b/src/cryfs/filesystem/CryNode.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace bf = boost::filesystem; @@ -123,15 +124,9 @@ void CryNode::stat(struct ::stat *result) const { result->st_nlink = 1; struct timespec now; clock_gettime(CLOCK_REALTIME, &now); -#ifdef __APPLE__ - result->st_atimespec = now; - result->st_mtimespec = now; - result->st_ctimespec = now; -#else result->st_atim = now; result->st_mtim = now; result->st_ctim = now; -#endif } else { (*_parent)->statChild(_key, result); } diff --git a/src/cryfs/filesystem/fsblobstore/DirBlob.cpp b/src/cryfs/filesystem/fsblobstore/DirBlob.cpp index b2915b0e..dc3a28da 100644 --- a/src/cryfs/filesystem/fsblobstore/DirBlob.cpp +++ b/src/cryfs/filesystem/fsblobstore/DirBlob.cpp @@ -9,6 +9,7 @@ #include "../CryDevice.h" #include "FileBlob.h" #include "SymlinkBlob.h" +#include using std::vector; using std::string; @@ -149,15 +150,9 @@ void DirBlob::statChildExceptSize(const Key &key, struct ::stat *result) const { result->st_gid = child.gid(); //TODO If possible without performance loss, then for a directory, st_nlink should return number of dir entries (including "." and "..") result->st_nlink = 1; -#ifdef __APPLE__ - result->st_atimespec = child.lastAccessTime(); - result->st_mtimespec = child.lastModificationTime(); - result->st_ctimespec = child.lastMetadataChangeTime(); -#else result->st_atim = child.lastAccessTime(); result->st_mtim = child.lastModificationTime(); result->st_ctim = child.lastMetadataChangeTime(); -#endif //TODO Move ceilDivision to general utils which can be used by cryfs as well result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, (off_t)512); result->st_blksize = _fsBlobStore->virtualBlocksizeBytes(); diff --git a/src/fspp/fstest/FsppNodeTest_Timestamps.h b/src/fspp/fstest/FsppNodeTest_Timestamps.h index 5e7cc7f0..6aae4913 100644 --- a/src/fspp/fstest/FsppNodeTest_Timestamps.h +++ b/src/fspp/fstest/FsppNodeTest_Timestamps.h @@ -5,6 +5,7 @@ #include "testutils/FsppNodeTest.h" #include "../fuse/FuseErrnoException.h" #include "testutils/TimestampTestUtils.h" +#include using namespace cpputils::time; using std::function; diff --git a/src/fspp/fstest/testutils/FileTest.h b/src/fspp/fstest/testutils/FileTest.h index 46833955..64119295 100644 --- a/src/fspp/fstest/testutils/FileTest.h +++ b/src/fspp/fstest/testutils/FileTest.h @@ -5,6 +5,7 @@ #include "FileSystemTest.h" #include #include +#include template class FileTest: public FileSystemTest { @@ -49,23 +50,13 @@ public: } void EXPECT_ATIME_EQ(struct timespec expected, struct stat st) { -#ifdef __APPLE__ - EXPECT_EQ(expected.tv_sec, st.st_atimespec.tv_sec); - EXPECT_EQ(expected.tv_nsec, st.st_atimespec.tv_nsec); -#else EXPECT_EQ(expected.tv_sec, st.st_atim.tv_sec); EXPECT_EQ(expected.tv_nsec, st.st_atim.tv_nsec); -#endif } void EXPECT_MTIME_EQ(struct timespec expected, struct stat st) { -#ifdef __APPLE__ - EXPECT_EQ(expected.tv_sec, st.st_mtimespec.tv_sec); - EXPECT_EQ(expected.tv_nsec, st.st_mtimespec.tv_nsec); -#else EXPECT_EQ(expected.tv_sec, st.st_mtim.tv_sec); EXPECT_EQ(expected.tv_nsec, st.st_mtim.tv_nsec); -#endif } }; diff --git a/src/fspp/fstest/testutils/TimestampTestUtils.h b/src/fspp/fstest/testutils/TimestampTestUtils.h index 4280541a..cfc15ae3 100644 --- a/src/fspp/fstest/testutils/TimestampTestUtils.h +++ b/src/fspp/fstest/testutils/TimestampTestUtils.h @@ -3,6 +3,7 @@ #define MESSMER_FSPP_FSTEST_TESTUTILS_TIMESTAMPTESTUTILS_H_ #include +#include class TimestampTestUtils { public: