]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify update_mtime
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 17:33:23 +0000 (19:33 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 18:31:54 +0000 (20:31 +0200)
src/ResultRetriever.cpp
src/Util.cpp
src/Util.hpp
src/ccache.cpp
src/legacy_util.cpp
src/legacy_util.hpp
src/manifest.cpp

index b0a6b5f0033d3ccfc3426dd6fcd9083725c01d73..9acd2f2b6e748fd1b8f3e05c03811c18e7502fa7 100644 (file)
@@ -104,7 +104,7 @@ ResultRetriever::on_entry_start(uint32_t entry_number,
 
       // Update modification timestamp to save the file from LRU cleanup (and,
       // if hard-linked, to make the object file newer than the source file).
-      update_mtime(raw_file->c_str());
+      Util::update_mtime(*raw_file);
     } else {
       cc_log("Copying to %s", dest_path.c_str());
       m_dest_fd = Fd(
index 652cf663345d9b4d1f592d4a10fcd35a7c988ae7..a6f2ac73f02688ffa569d967dc7f5cbb5261428b 100644 (file)
 #  include <pwd.h>
 #endif
 
+#ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+#endif
+
 #ifdef HAVE_LINUX_FS_H
 #  include <linux/magic.h>
 #  include <sys/statfs.h>
@@ -1307,6 +1311,16 @@ unsetenv(const std::string& name)
 #endif
 }
 
+void
+update_mtime(const std::string& path)
+{
+#ifdef HAVE_UTIMES
+  utimes(path.c_str(), nullptr);
+#else
+  utime(path.c_str(), nullptr);
+#endif
+}
+
 void
 wipe_path(const std::string& path)
 {
index 8b57199ce0aa85a8e5ef62114c210db777463627..9434b8d0ff98d9689dc3c6ec3f8ddc603ffad93d 100644 (file)
@@ -427,6 +427,9 @@ bool unlink_tmp(const std::string& path,
 // Unset environment variable `name`.
 void unsetenv(const std::string& name);
 
+// Set mtime of `path` to the current timestamp.
+void update_mtime(const std::string& path);
+
 // Remove `path` (and its contents if it's a directory). A non-existing path is
 // not considered an error.
 //
index 885e7fa7d22b3de93887679589d215084934e438..8d58ef7b514900ad160def209e6c31f63e912d23 100644 (file)
@@ -185,7 +185,7 @@ clean_up_internal_tempdir(const Config& config)
     return;
   }
 
-  update_mtime(config.cache_dir().c_str());
+  Util::update_mtime(config.cache_dir());
 
   const std::string& temp_dir = config.temporary_dir();
   if (!Stat::lstat(temp_dir)) {
@@ -1706,7 +1706,7 @@ from_cache(Context& ctx, enum fromcache_call_mode mode)
     return nullopt;
   } else {
     // Update modification timestamp to save file from LRU cleanup.
-    update_mtime(ctx.result_path().c_str());
+    Util::update_mtime(ctx.result_path());
   }
 
   cc_log("Succeeded getting cached result");
index 09937a429b6ab9abe10dd1305d1ccf501a6696d1..d736f4b3be25f5c687f6a72a64a18cb5f1d48925 100644 (file)
 #  include <sys/time.h>
 #endif
 
-// Update the modification time of a file in the cache to save it from LRU
-// cleanup.
-void
-update_mtime(const char* path)
-{
-#ifdef HAVE_UTIMES
-  utimes(path, nullptr);
-#else
-  utime(path, NULL);
-#endif
-}
-
 // If exit() already has been called, call _exit(), otherwise exit(). This is
 // used to avoid calling exit() inside an atexit handler.
 void
index 523e1621e92d2ada591ba151d0b2d6e9c399c4e2..d032a1531a06cf9d96ac231d38ac3d12add7aad5 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <string>
 
-void update_mtime(const char* path);
 void x_exit(int status) ATTR_NORETURN;
 int x_rename(const char* oldpath, const char* newpath);
 void set_cloexec_flag(int fd);
index 6238f08823317701a708e1821bd7cd40bad2c8cb..b0b7d4cd8f2988bd41c5eea4d34d08dc4163c7fe 100644 (file)
@@ -482,7 +482,7 @@ manifest_get(const Context& ctx, const std::string& path)
     mf = read_manifest(path);
     if (mf) {
       // Update modification timestamp to save files from LRU cleanup.
-      update_mtime(path.c_str());
+      Util::update_mtime(path);
     } else {
       cc_log("No such manifest file");
       return nullopt;