git-bundle: prevent overwriting existing bundles
[gitweb.git] / builtin-bundle.c
index ca3de60e44267e8592b86a9632a25f66c5eedea8..55f6d0abcf44b75e9cd4f88537f0682fda3feb93 100644 (file)
@@ -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));