]> asedeno.scripts.mit.edu Git - git.git/blobdiff - fast-import.c
Improve use of lockfile API
[git.git] / fast-import.c
index 74597c901c4e7bff7ed5344719c3162b4e096c3a..3609c24288dedb5b5e1b46d77ebfce6c305a434e 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));
@@ -1545,10 +1546,18 @@ static void dump_marks(void)
        }
 
        dump_marks_helper(f, 0, marks);
-       fclose(f);
-       if (commit_lock_file(&mark_lock))
+       if (ferror(f) || fclose(f))
                failure |= error("Unable to write marks file %s: %s",
                        mark_file, strerror(errno));
+       /*
+        * Since the lock file was fdopen()'ed and then fclose()'ed above,
+        * assign -1 to the lock file descriptor so that commit_lock_file()
+        * won't try to close() it.
+        */
+       mark_lock.fd = -1;
+       if (commit_lock_file(&mark_lock))
+               failure |= error("Unable to write commit file %s: %s",
+                       mark_file, strerror(errno));
 }
 
 static int read_next_command(void)