]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Let --inspect retain atime if possible
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 26 Jan 2024 19:20:20 +0000 (20:20 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Jan 2024 09:50:16 +0000 (10:50 +0100)
For storage that relies on atime for LRU cleanup purposes, it makes
sense not to affect atime when inspecting cache entries.

src/core/mainoptions.cpp

index 6824ebd1737021fe3e3568cffee602b3be64a6d6..9ad83588c553a30721525386de6fdea8c85a31fb 100644 (file)
@@ -210,7 +210,17 @@ read_from_path_or_stdin(const std::string& path)
 static int
 inspect_path(const std::string& path)
 {
+  std::optional<util::DirEntry> orig_dir_entry;
+  if (path != "-") {
+    orig_dir_entry = util::DirEntry(path);
+    orig_dir_entry->refresh();
+  }
   const auto cache_entry_data = read_from_path_or_stdin(path);
+  if (orig_dir_entry) {
+    util::set_timestamps(
+      path, orig_dir_entry->mtime(), orig_dir_entry->atime());
+  }
+
   if (!cache_entry_data) {
     PRINT(stderr, "Error: {}\n", cache_entry_data.error());
     return EXIT_FAILURE;