]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move utimes/utime into an update_mtime function
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 17 Feb 2010 19:08:13 +0000 (20:08 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 17 Feb 2010 19:10:00 +0000 (20:10 +0100)
ccache.c
ccache.h
util.c

index 3cd8123d7f798d743b1b6ebb43735e0d9d1124c5..bae31443607bff343002f52c1b55b7a6999cbd6a 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -949,21 +949,13 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest
                }
        }
 
-       /* update timestamps for LRU cleanup
-          also gives output_file a sensible mtime when hard-linking (for make) */
-#ifdef HAVE_UTIMES
-       utimes(object_path, NULL);
-       utimes(stderr_file, NULL);
+       /* Update modification timestamps to save files from LRU cleanup.
+          Also gives files a sensible mtime when hard-linking. */
+       update_mtime(object_path);
+       update_mtime(stderr_file);
        if (produce_dep_file) {
-               utimes(dep_file, NULL);
+               update_mtime(dep_file);
        }
-#else
-       utime(object_path, NULL);
-       utime(stderr_file, NULL);
-       if (produce_dep_file) {
-               utime(dep_file, NULL);
-       }
-#endif
 
        if (generating_dependencies && mode != FROMCACHE_DIRECT_MODE) {
                /* Store the dependency file in the cache. */
@@ -1007,12 +999,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest
                if (manifest_put(manifest_path, object_hash, included_files)) {
                        cc_log("Added object file hash to manifest %s\n",
                                manifest_path);
-                       /* Update timestamp for LRU cleanup. */
-#ifdef HAVE_UTIMES
-                       utimes(manifest_path, NULL);
-#else
-                       utime(manifest_path, NULL);
-#endif
+                       update_mtime(manifest_path);
                } else {
                        cc_log("Failed to add object file hash to manifest\n");
                }
index cff071559d4ea4243400d1dd7ddaa8d3c982656d..a44f866dd7792744019b66e2f031347efe7f832a 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -123,6 +123,7 @@ const char *get_home_directory(void);
 char *get_cwd();
 size_t common_dir_prefix_length(const char *s1, const char *s2);
 char *get_relative_path(const char *from, const char *to);
+void update_mtime(const char *path);
 
 void stats_update(enum stats stat);
 void stats_zero(void);
diff --git a/util.c b/util.c
index b577ad4592f1afcec5391c9ae6613ef30ee971ef..564095159a837521d45d76fdd7e129ac143c6bae 100644 (file)
--- a/util.c
+++ b/util.c
@@ -756,3 +756,17 @@ char *get_relative_path(const char *from, const char *to)
        }
        return result;
 }
+
+/*
+ * 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, NULL);
+#else
+       utime(path, NULL);
+#endif
+}