Code

bundle, fast-import: detect write failure
authorJim Meyering <jim@meyering.net>
Thu, 10 Jan 2008 08:54:25 +0000 (09:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jan 2008 09:08:11 +0000 (01:08 -0800)
I noticed some unchecked writes.  This fixes them.

* bundle.c (create_bundle): Die upon write failure.
* fast-import.c (keep_pack): Die upon write or close failure.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle.c
fast-import.c

index be204d8a228ab5218a603cdcf3ebd17e95ad8d90..316aa7420d8bd647e304d21c6ca4a9b9cbe5548a 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -320,9 +320,9 @@ int create_bundle(struct bundle_header *header, const char *path,
        for (i = 0; i < revs.pending.nr; i++) {
                struct object *object = revs.pending.objects[i].item;
                if (object->flags & UNINTERESTING)
-                       write(rls.in, "^", 1);
-               write(rls.in, sha1_to_hex(object->sha1), 40);
-               write(rls.in, "\n", 1);
+                       write_or_die(rls.in, "^", 1);
+               write_or_die(rls.in, sha1_to_hex(object->sha1), 40);
+               write_or_die(rls.in, "\n", 1);
        }
        if (finish_command(&rls))
                return error ("pack-objects died");
index 74597c901c4e7bff7ed5344719c3162b4e096c3a..82e916133982800420e77d1824a2714dd120550e 100644 (file)
@@ -878,8 +878,9 @@ static char *keep_pack(char *curr_index_name)
        keep_fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
        if (keep_fd < 0)
                die("cannot create keep file");
-       write(keep_fd, keep_msg, strlen(keep_msg));
-       close(keep_fd);
+       write_or_die(keep_fd, keep_msg, strlen(keep_msg));
+       if (close(keep_fd))
+               die("failed to write keep file");
 
        snprintf(name, sizeof(name), "%s/pack/pack-%s.pack",
                 get_object_directory(), sha1_to_hex(pack_data->sha1));