]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Unlink destination file before renames
authorRamiro Polla <ramiro.polla@gmail.com>
Thu, 15 Jul 2010 17:30:32 +0000 (14:30 -0300)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 16 Jul 2010 13:42:51 +0000 (15:42 +0200)
Windows' rename() will not overwrite existing files.

ccache.c
manifest.c
util.c

index 5b8a7460adbbb9bc4266de32a4d0f8e8a39cbaea..a2660ad5bb408ddde3929abe82a075e565a70c1b 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -661,6 +661,7 @@ static void to_cache(ARGS *args)
                char *tmp_stderr2;
 
                x_asprintf(&tmp_stderr2, "%s.tmp.stderr2.%s", cached_obj, tmp_string());
+               unlink(tmp_stderr2);
                if (rename(tmp_stderr, tmp_stderr2)) {
                        cc_log("Failed to rename %s to %s", tmp_stderr, tmp_stderr2);
                        failed();
index 4ba19c7772f28dfe115603817e0a1be5ef2fda46..c759f1cb81b9691f15155709d5a7fe32d4b69cfb 100644 (file)
@@ -673,6 +673,7 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash,
 
        add_object_entry(mf, object_hash, included_files);
        if (write_manifest(f2, mf)) {
+               unlink(manifest_path);
                if (rename(tmp_file, manifest_path) == 0) {
                        ret = 1;
                } else {
diff --git a/util.c b/util.c
index 6f7c781d378d13d77e03ef13209554b2435238e3..d02f16bbf6a486023978c350c3ae399e36dac11a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -329,6 +329,7 @@ move_uncompressed_file(const char *src, const char *dest, int compress_dest)
        if (compress_dest) {
                return move_file(src, dest, compress_dest);
        } else {
+               unlink(dest);
                return rename(src, dest);
        }
 }