{"thread":{"id":"7159","subject":"[PATCH 3/3] git-bundle: prevent overwriting existing bundles","startedAt":"2007-03-09T02:50:06Z","lastAt":"2007-03-09T03:05:01Z","messageCount":3,"participants":["Johannes Schindelin","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"36661","messageId":"Pine.LNX.4.63.0703090348480.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7159","inReplyTo":null,"subject":"[PATCH 3/3] git-bundle: prevent overwriting existing bundles","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-09T02:50:06Z","receivedAt":"2007-03-09T02:50:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nNot only does it prevent accidentally losing older bundles, but it\nalso fixes a subtle bug: when writing into an existing bundle,\ngit-pack-objects would not truncate the bundle. Therefore,\nfetching from the bundle would trigger an error in unpack-objects:\n\"fatal: pack has junk at the end\".\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tAlternatively, we could use O_TRUNC instead of O_EXCL, but\n\tI think it makes sense to refuse to overwrite existing\n\tbundles.\n\n\tMark, I guess this is what triggered the bug you were reporting.\n\n builtin-bundle.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex ca3de60..5ebba0b 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -268,9 +268,9 @@ static int create_bundle(struct bundle_header *header, const char *path,\n \tstruct rev_info revs;\n \n \tbundle_fd = (!strcmp(path, \"-\") ? 1 :\n-\t\t\topen(path, O_CREAT | O_WRONLY, 0666));\n+\t\t\topen(path, O_CREAT | O_EXCL | O_WRONLY, 0666));\n \tif (bundle_fd < 0)\n-\t\treturn error(\"Could not write to '%s'\", path);\n+\t\treturn error(\"Could not create '%s'\", path);\n \n \t/* write signature */\n \twrite_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));\n-- \n1.5.0.3.2601.gc1e5-dirty\n"},{"id":"36662","messageId":"20070309025902.GE32211@spearce.org","threadId":"7159","inReplyTo":"Pine.LNX.4.63.0703090348480.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 3/3] git-bundle: prevent overwriting existing bundles","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-09T02:59:02Z","receivedAt":"2007-03-09T02:59:02Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>  \tif (bundle_fd < 0)\n> -\t\treturn error(\"Could not write to '%s'\", path);\n> +\t\treturn error(\"Could not create '%s'\", path);\n\nI hate to be a nit, but what about?\n\n> +\t\treturn error(\"Could not create '%s': %s\", path, strerror(errno));\n\n-- \nShawn.\n"},{"id":"36663","messageId":"Pine.LNX.4.63.0703090403090.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7159","inReplyTo":"20070309025902.GE32211@spearce.org","subject":"Re: [PATCH 3/3] git-bundle: prevent overwriting existing bundles","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-09T03:05:01Z","receivedAt":"2007-03-09T03:05:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 8 Mar 2007, Shawn O. Pearce wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> >  \tif (bundle_fd < 0)\n> > -\t\treturn error(\"Could not write to '%s'\", path);\n> > +\t\treturn error(\"Could not create '%s'\", path);\n> \n> I hate to be a nit, but what about?\n> \n> > +\t\treturn error(\"Could not create '%s': %s\", path, strerror(errno));\n\nACK\n"}]}