]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Rename temporary object file to cached object file if possible
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 9 May 2010 15:50:20 +0000 (17:50 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 9 May 2010 15:50:20 +0000 (17:50 +0200)
This avoids copying the object file unnecessarily in the common case when we
store object files uncompressed in the cache.

ccache.c
ccache.h
util.c

index b2a55c2ec9a53937402da899035a5ca260f0e97f..fe229814f1c69230b259860a6e9c24dec6cf5da1 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -594,7 +594,8 @@ static void to_cache(ARGS *args)
                failed();
        }
        if (st.st_size > 0) {
-               if (move_file(tmp_stderr, cached_stderr, compress) != 0) {
+               if (move_uncompressed_file(tmp_stderr, cached_stderr,
+                                          compress) != 0) {
                        cc_log("Failed to move %s to %s",
                               tmp_stderr, cached_stderr);
                        stats_update(STATS_ERROR);
@@ -604,7 +605,7 @@ static void to_cache(ARGS *args)
        } else {
                unlink(tmp_stderr);
        }
-       if (move_file(tmp_obj, cached_obj, compress) != 0) {
+       if (move_uncompressed_file(tmp_obj, cached_obj, compress) != 0) {
                cc_log("Failed to move %s to %s", tmp_obj, cached_obj);
                stats_update(STATS_ERROR);
                failed();
index 227734410310dcc84e7817d59b87b96fa428243c..9aae3ff21afe7432348da945928d85ee28906118 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -70,6 +70,8 @@ void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void copy_fd(int fd_in, int fd_out);
 int copy_file(const char *src, const char *dest, int compress_dest);
 int move_file(const char *src, const char *dest, int compress_dest);
+int move_uncompressed_file(const char *src, const char *dest,
+                          int compress_dest);
 int test_if_compressed(const char *filename);
 
 int create_dir(const char *dir);
diff --git a/util.c b/util.c
index 7ddd5056ffd9fdba16839b9db7f5de0e71128631..4ac7109057ee9fc68edb7a81eb6993de61d5c19c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -259,6 +259,20 @@ int move_file(const char *src, const char *dest, int compress_dest)
        return ret;
 }
 
+/*
+ * Like move_file(), but assumes that src is uncompressed and that src and dest
+ * are on the same file system.
+ */
+int
+move_uncompressed_file(const char *src, const char *dest, int compress_dest)
+{
+       if (compress_dest) {
+               return move_file(src, dest, compress_dest);
+       } else {
+               return rename(src, dest);
+       }
+}
+
 /* test if a file is zlib compressed */
 int test_if_compressed(const char *filename)
 {