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

[PATCH 3/3] git-bundle: prevent overwriting existing bundles

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 9, 2007, 02:50 UTC
Message-ID
<Pine.LNX.4.63.0703090348480.22628@wbgn013.biozentrum.uni-wuerzburg.de>

Not only does it prevent accidentally losing older bundles, but it also fixes a subtle bug: when writing into an existing bundle, git-pack-objects would not truncate the bundle. Therefore, fetching from the bundle would trigger an error in unpack-objects: "fatal: pack has junk at the end".

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	Alternatively, we could use O_TRUNC instead of O_EXCL, but
	I think it makes sense to refuse to overwrite existing
	bundles.
	Mark, I guess this is what triggered the bug you were reporting.
 builtin-bundle.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-bundle.c b/builtin-bundle.c
index ca3de60..5ebba0b 100644
--- a/builtin-bundle.c
+++ b/builtin-bundle.c
@@ -268,9 +268,9 @@ static int create_bundle(struct bundle_header *header, const char *path,
 	struct rev_info revs;
 
 	bundle_fd = (!strcmp(path, "-") ? 1 :
-			open(path, O_CREAT | O_WRONLY, 0666));
+			open(path, O_CREAT | O_EXCL | O_WRONLY, 0666));
 	if (bundle_fd < 0)
-		return error("Could not write to '%s'", path);
+		return error("Could not create '%s'", path);
 
 	/* write signature */
 	write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
-- 
1.5.0.3.2601.gc1e5-dirty
Next: Shawn O. Pearce
Message 1 of 3 in “git-bundle: prevent overwriting existing bundles”
  1. 3/3 git-bundle: prevent overwriting existing bundlesJohannes Schindelin, Mar 9, 2007
  2. Shawn O. PearceMar 9, 2007
  3. Johannes SchindelinMar 9, 2007

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.