summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-11-17 20:32:04 +0100
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-11-18 02:12:28 +0100
commit472d4d858bed9758b2e9300e544417c0d9d43623 (patch)
tree8d5200f7c8d2caf2c056568b289f3fcf109ac96a /src
parent2cbca8b06cb7cab08d916438a63e19734256b3fa (diff)
downloadlibgit2-472d4d858bed9758b2e9300e544417c0d9d43623.tar.gz
Don't overwrite existing objects
It's redundant to do this (git doesn't) and Windows doesn't allow us to overwrite a read-only file (which objects are). Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src')
-rw-r--r--src/odb_loose.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 8c0331834..57a0b0a8e 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -670,6 +670,17 @@ static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
return git__rethrow(error, "Failed to write loose backend");
stream->finished = 1;
+
+ /*
+ * Don't try to add an existing object to the repository. This
+ * is what git does and allows us to sidestep the fact that
+ * we're not allowed to overwrite a read-only file on Windows.
+ */
+ if (git_futils_exists(final_path) == GIT_SUCCESS) {
+ git_filebuf_cleanup(&stream->fbuf);
+ return GIT_SUCCESS;
+ }
+
return git_filebuf_commit_at(&stream->fbuf, final_path, GIT_OBJECT_FILE_MODE);
}