aboutsummaryrefslogtreecommitdiff
path: root/index-pack.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2006-11-01 17:06:24 -0500
committerJunio C Hamano <junkio@cox.net>2006-11-03 00:24:07 -0800
commit9ca4a201eaf0c58dbc7184cb2d5ab01c48cb7447 (patch)
tree40d15a0009df42b91567ea938adb389ade0a61a0 /index-pack.c
parentda093d37506f034bfb14e6de26cce9c14b1a1216 (diff)
downloadgit-9ca4a201eaf0c58dbc7184cb2d5ab01c48cb7447.tar.gz
git-9ca4a201eaf0c58dbc7184cb2d5ab01c48cb7447.tar.xz
have index-pack create .keep file more carefully
If by chance we receive a pack which content (list of objects) matches another pack that we already have, and if that pack is marked with a .keep file, then we should not overwrite it. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'index-pack.c')
-rw-r--r--index-pack.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/index-pack.c b/index-pack.c
index a3b55f9b0..8d64a883a 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -788,14 +788,17 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
get_object_directory(), sha1_to_hex(sha1));
keep_name = name;
}
- keep_fd = open(keep_name, O_RDWR | O_CREAT, 0600);
- if (keep_fd < 0)
- die("cannot write keep file");
- if (keep_msg_len > 0) {
- write_or_die(keep_fd, keep_msg, keep_msg_len);
- write_or_die(keep_fd, "\n", 1);
+ keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);
+ if (keep_fd < 0) {
+ if (errno != EEXIST)
+ die("cannot write keep file");
+ } else {
+ if (keep_msg_len > 0) {
+ write_or_die(keep_fd, keep_msg, keep_msg_len);
+ write_or_die(keep_fd, "\n", 1);
+ }
+ close(keep_fd);
}
- close(keep_fd);
}
if (final_pack_name != curr_pack_name) {