]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Support Stat::{atim,ctim,mtim} on macOS
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 4 Aug 2022 18:01:40 +0000 (20:01 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 20 Aug 2022 12:17:37 +0000 (14:17 +0200)
(cherry picked from commit bcdaeb5c6082717bac984ab2ffafd0bdee552458)

cmake/GenerateConfigurationFile.cmake
cmake/config.h.in
src/InodeCache.cpp
src/Stat.hpp
unittest/test_Stat.cpp

index 5d106ff9679825f32bc22d1dec953894eea89ca8..8e2c2202f61926a8bb16905455516217aeba7808 100644 (file)
@@ -68,6 +68,12 @@ check_struct_has_member("struct stat" st_ctim sys/stat.h
                         HAVE_STRUCT_STAT_ST_CTIM LANGUAGE CXX)
 check_struct_has_member("struct stat" st_mtim sys/stat.h
                         HAVE_STRUCT_STAT_ST_MTIM LANGUAGE CXX)
+check_struct_has_member("struct stat" st_atimespec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_ATIMESPEC LANGUAGE CXX)
+check_struct_has_member("struct stat" st_ctimespec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_CTIMESPEC LANGUAGE CXX)
+check_struct_has_member("struct stat" st_mtimespec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE CXX)
 check_struct_has_member("struct statfs" f_fstypename sys/mount.h
                         HAVE_STRUCT_STATFS_F_FSTYPENAME LANGUAGE CXX)
 
index e5cd5e7ba827538a9121fd863daf377a5c9be487..f575c53f363da3c3a5a419649d90e4ea67e72c7d 100644 (file)
 // Define if "st_mtim" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_MTIM
 
+// Define if "st_atimespec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_ATIMESPEC
+
+// Define if "st_ctimespec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_CTIMESPEC
+
+// Define if "st_mtimespec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC
+
 // Define if you have the "syslog" function.
 #cmakedefine HAVE_SYSLOG
 
index 15a3392804f456840202448bf919f85515b94bbd..db411c35b8b4b40186f2540349924a87a5d0afa6 100644 (file)
@@ -90,17 +90,9 @@ struct InodeCache::Key
   dev_t st_dev;
   ino_t st_ino;
   mode_t st_mode;
-#ifdef HAVE_STRUCT_STAT_ST_MTIM
   timespec st_mtim;
-#else
-  time_t st_mtim;
-#endif
-#ifdef HAVE_STRUCT_STAT_ST_CTIM
   timespec st_ctim; // Included for sanity checking.
-#else
-  time_t st_ctim; // Included for sanity checking.
-#endif
-  off_t st_size; // Included for sanity checking.
+  off_t st_size;    // Included for sanity checking.
   bool sloppy_time_macros;
 };
 
@@ -188,16 +180,8 @@ InodeCache::hash_inode(const std::string& path,
   key.st_dev = stat.device();
   key.st_ino = stat.inode();
   key.st_mode = stat.mode();
-#ifdef HAVE_STRUCT_STAT_ST_MTIM
   key.st_mtim = stat.mtim();
-#else
-  key.st_mtim = stat.mtime();
-#endif
-#ifdef HAVE_STRUCT_STAT_ST_CTIM
   key.st_ctim = stat.ctim();
-#else
-  key.st_ctim = stat.ctime();
-#endif
   key.st_size = stat.size();
 
   Hash hash;
index 53aed648f9a9b77370943fe6e15c91e24a7c1df0..e31a6b1306d64af0fdb2e98a2380ffb040bb8628 100644 (file)
@@ -270,6 +270,8 @@ Stat::atim() const
 {
 #if defined(_WIN32) || defined(HAVE_STRUCT_STAT_ST_ATIM)
   return m_stat.st_atim;
+#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
+  return m_stat.st_atimespec;
 #else
   return {m_stat.st_atime, 0};
 #endif
@@ -280,6 +282,8 @@ Stat::ctim() const
 {
 #if defined(_WIN32) || defined(HAVE_STRUCT_STAT_ST_CTIM)
   return m_stat.st_ctim;
+#elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
+  return m_stat.st_ctimespec;
 #else
   return {m_stat.st_ctime, 0};
 #endif
@@ -290,6 +294,8 @@ Stat::mtim() const
 {
 #if defined(_WIN32) || defined(HAVE_STRUCT_STAT_ST_MTIM)
   return m_stat.st_mtim;
+#elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
+  return m_stat.st_mtimespec;
 #else
   return {m_stat.st_mtime, 0};
 #endif
index 3a3586e29bf8295a5e023da95ab8aadc5dc9272c..a6e41b338cbc469ae868b533d523f757156fcdf9 100644 (file)
@@ -284,6 +284,9 @@ TEST_CASE("Return values when file exists")
 #  ifdef HAVE_STRUCT_STAT_ST_CTIM
   CHECK(stat.ctim().tv_sec == st.st_ctim.tv_sec);
   CHECK(stat.ctim().tv_nsec == st.st_ctim.tv_nsec);
+#  elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
+  CHECK(stat.ctim().tv_sec == st.st_ctimespec.tv_sec);
+  CHECK(stat.ctim().tv_nsec == st.st_ctimespec.tv_nsec);
 #  else
   CHECK(stat.ctim().tv_sec == st.st_ctime);
   CHECK(stat.ctim().tv_nsec == 0);
@@ -292,6 +295,9 @@ TEST_CASE("Return values when file exists")
 #  ifdef HAVE_STRUCT_STAT_ST_MTIM
   CHECK(stat.mtim().tv_sec == st.st_mtim.tv_sec);
   CHECK(stat.mtim().tv_nsec == st.st_mtim.tv_nsec);
+#  elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
+  CHECK(stat.mtim().tv_sec == st.st_mtimespec.tv_sec);
+  CHECK(stat.mtim().tv_nsec == st.st_mtimespec.tv_nsec);
 #  else
   CHECK(stat.mtim().tv_sec == st.st_mtime);
   CHECK(stat.mtim().tv_nsec == 0);