From: Joel Rosdahl Date: Fri, 31 Jul 2020 17:33:23 +0000 (+0200) Subject: C++-ify update_mtime X-Git-Tag: v4.0~243 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d94f940e69cb828580e31b85d29a26ab5e50d9c8;p=thirdparty%2Fccache.git C++-ify update_mtime --- diff --git a/src/ResultRetriever.cpp b/src/ResultRetriever.cpp index b0a6b5f00..9acd2f2b6 100644 --- a/src/ResultRetriever.cpp +++ b/src/ResultRetriever.cpp @@ -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( diff --git a/src/Util.cpp b/src/Util.cpp index 652cf6633..a6f2ac73f 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -33,6 +33,10 @@ # include #endif +#ifdef HAVE_SYS_TIME_H +# include +#endif + #ifdef HAVE_LINUX_FS_H # include # include @@ -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) { diff --git a/src/Util.hpp b/src/Util.hpp index 8b57199ce..9434b8d0f 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -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. // diff --git a/src/ccache.cpp b/src/ccache.cpp index 885e7fa7d..8d58ef7b5 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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"); diff --git a/src/legacy_util.cpp b/src/legacy_util.cpp index 09937a429..d736f4b3b 100644 --- a/src/legacy_util.cpp +++ b/src/legacy_util.cpp @@ -31,18 +31,6 @@ # include #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 diff --git a/src/legacy_util.hpp b/src/legacy_util.hpp index 523e1621e..d032a1531 100644 --- a/src/legacy_util.hpp +++ b/src/legacy_util.hpp @@ -22,7 +22,6 @@ #include -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); diff --git a/src/manifest.cpp b/src/manifest.cpp index 6238f0882..b0b7d4cd8 100644 --- a/src/manifest.cpp +++ b/src/manifest.cpp @@ -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;