git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/6] have index-pack create .keep file more carefully

From
Nicolas Pitre <nico@cam.org>
Date
Nov 1, 2006, 22:06 UTC
Message-ID
<11624187871572-git-send-email-nico@cam.org>
In-Reply-To
<1162418786390-git-send-email-nico@cam.org>

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>
---
 index-pack.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/index-pack.c b/index-pack.c
index a3b55f9..8d64a88 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -788,14 +788,17 @@ static void final(const char *final_pack
 				 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) {
-- 
1.4.3.3.g87b2-dirty
Previous: Nicolas PitreNext: Nicolas Pitre
Message 5 of 13 in “Allow pack header preprocessing before unpack-objects/index-pack.”
  1. 1/6 Allow pack header preprocessing before unpack-objects/index-pack.Nicolas Pitre, Nov 1, 2006
  2. 2/6 Teach receive-pack how to keep pack files based on object count.Nicolas Pitre, Nov 1, 2006
  3. 3/6 git-fetch can use both --thin and --keep with fetch-pack nowNicolas Pitre, Nov 1, 2006
  4. 4/6 improve fetch-pack's handling of kept packsNicolas Pitre, Nov 1, 2006
  5. 5/6 have index-pack create .keep file more carefullyNicolas Pitre, Nov 1, 2006
  6. 6/6 remove .keep pack lock files when done with refs updateNicolas Pitre, Nov 1, 2006
  7. Shawn PearceNov 2, 2006
  8. Junio C HamanoNov 2, 2006
  9. Nicolas PitreNov 2, 2006
  10. Nicolas PitreNov 2, 2006
  11. Junio C HamanoNov 3, 2006
  12. Junio C HamanoNov 1, 2006
  13. Nicolas PitreNov 2, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.