git-bundle: prevent overwriting existing bundles
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Mar 9, 2007 at 03:50 UTC
2e578f9a4f08ade4e8da52614c566e5dc1c8ca00
1 file changed
+2
-2
builtin-bundle.c
+2
-2
@@ -268,9 +268,9 @@ static int create_bundle(struct bundle_header *header, const char *path,
268
struct rev_info revs;
269
270
bundle_fd = (!strcmp(path, "-") ? 1 :
271
- open(path, O_CREAT | O_WRONLY, 0666));
271
+ open(path, O_CREAT | O_EXCL | O_WRONLY, 0666));
272
if (bundle_fd < 0)
273
- return error("Could not write to '%s'", path);
273
+ return error("Could not create '%s': %s", path, strerror(errno));
274
275
/* write signature */
276
write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));