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>
This commit is contained in:
Johannes Schindelin 2007-03-09 03:50:06 +01:00 коммит произвёл Junio C Hamano
Родитель d58c6184e3
Коммит 2e578f9a4f
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -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': %s", path, strerror(errno));
/* write signature */
write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));