@matheusbsbs / matheus-bagliano / commits / 9ca4a201ea
Fork 0

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>

Nicolas Pitre committed Nov 1, 2006 at 17:06 UTC 9ca4a201eaf0c58dbc7184cb2d5ab01c48cb7447
1 file changed +10 -7
index-pack.c
+10 -7
@@ -788,14 +788,17 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
788 get_object_directory(), sha1_to_hex(sha1));
789 keep_name = name;
790 }
791 - keep_fd = open(keep_name, O_RDWR | O_CREAT, 0600);
792 - if (keep_fd < 0)
793 - die("cannot write keep file");
794 - if (keep_msg_len > 0) {
795 - write_or_die(keep_fd, keep_msg, keep_msg_len);
796 - write_or_die(keep_fd, "\n", 1);
791 + keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);
792 + if (keep_fd < 0) {
793 + if (errno != EEXIST)
794 + die("cannot write keep file");
795 + } else {
796 + if (keep_msg_len > 0) {
797 + write_or_die(keep_fd, keep_msg, keep_msg_len);
798 + write_or_die(keep_fd, "\n", 1);
799 + }
800 + close(keep_fd);
801 }
798 - close(keep_fd);
802 }
803
804 if (final_pack_name != curr_pack_name) {