]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Support subsecond mtime/atime for --cleanup and --trim-dir
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 10 Aug 2021 18:32:43 +0000 (20:32 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 10 Aug 2021 18:32:43 +0000 (20:32 +0200)
src/core/mainoptions.cpp
src/storage/primary/PrimaryStorage_cleanup.cpp

index 2c301d970aef30cd81eb41390414445b72eaeabc..a5ccf6eeb6d083e221b5e8d5238979023fe0670f 100644 (file)
@@ -218,11 +218,11 @@ trim_dir(const std::string& dir,
   });
 
   std::sort(files.begin(), files.end(), [&](const auto& f1, const auto& f2) {
-    if (trim_lru_mtime) {
-      return f1.stat.mtime() < f2.stat.mtime();
-    } else {
-      return f1.stat.atime() < f2.stat.atime();
-    }
+    const auto ts_1 = trim_lru_mtime ? f1.stat.mtim() : f1.stat.atim();
+    const auto ts_2 = trim_lru_mtime ? f2.stat.mtim() : f2.stat.atim();
+    const auto ns_1 = 1'000'000'000ULL * ts_1.tv_sec + ts_1.tv_nsec;
+    const auto ns_2 = 1'000'000'000ULL * ts_2.tv_sec + ts_2.tv_nsec;
+    return ns_1 < ns_2;
   });
 
   uint64_t size_after = size_before;
index fd89cf0351cd92263883ba310218aa7d590881ed..6f3790f9cfa929473dfb68d729431d7f62eba7cb 100644 (file)
@@ -126,7 +126,11 @@ PrimaryStorage::clean_dir(const std::string& subdir,
 
   // Sort according to modification time, oldest first.
   std::sort(files.begin(), files.end(), [](const auto& f1, const auto& f2) {
-    return f1.lstat().mtime() < f2.lstat().mtime();
+    const auto ts_1 = f1.lstat().mtim();
+    const auto ts_2 = f2.lstat().mtim();
+    const auto ns_1 = 1'000'000'000ULL * ts_1.tv_sec + ts_1.tv_nsec;
+    const auto ns_2 = 1'000'000'000ULL * ts_2.tv_sec + ts_2.tv_nsec;
+    return ns_1 < ns_2;
   });
 
   LOG("Before cleanup: {:.0f} KiB, {:.0f} files",