From: Ramiro Polla Date: Thu, 15 Jul 2010 17:30:32 +0000 (-0300) Subject: Unlink destination file before renames X-Git-Tag: v3.1~192 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aebc480793d00a41f672606cecb9ab1f2fd4331b;p=thirdparty%2Fccache.git Unlink destination file before renames Windows' rename() will not overwrite existing files. --- diff --git a/ccache.c b/ccache.c index 5b8a7460a..a2660ad5b 100644 --- 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(); diff --git a/manifest.c b/manifest.c index 4ba19c777..c759f1cb8 100644 --- a/manifest.c +++ b/manifest.c @@ -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 6f7c781d3..d02f16bbf 100644 --- 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); } }