fast-import.c: fix regression due to strbuf conversion
[gitweb.git] / pack-write.c
index 1cf5f7c9f0956a457de03c64238d298a9d996984..979bdfff7c516ada7fb36281a22b41d303d1b99c 100644 (file)
@@ -45,7 +45,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
                static char tmpfile[PATH_MAX];
                snprintf(tmpfile, sizeof(tmpfile),
                         "%s/tmp_idx_XXXXXX", get_object_directory());
-               fd = mkstemp(tmpfile);
+               fd = xmkstemp(tmpfile);
                index_name = xstrdup(tmpfile);
        } else {
                unlink(index_name);
@@ -179,3 +179,29 @@ void fixup_pack_header_footer(int pack_fd,
        SHA1_Final(pack_file_sha1, &c);
        write_or_die(pack_fd, pack_file_sha1, 20);
 }
+
+char *index_pack_lockfile(int ip_out)
+{
+       int len, s;
+       char packname[46];
+
+       /*
+        * The first thing we expects from index-pack's output
+        * is "pack\t%40s\n" or "keep\t%40s\n" (46 bytes) where
+        * %40s is the newly created pack SHA1 name.  In the "keep"
+        * case, we need it to remove the corresponding .keep file
+        * later on.  If we don't get that then tough luck with it.
+        */
+       for (len = 0;
+                len < 46 && (s = xread(ip_out, packname+len, 46-len)) > 0;
+                len += s);
+       if (len == 46 && packname[45] == '\n' &&
+               memcmp(packname, "keep\t", 5) == 0) {
+               char path[PATH_MAX];
+               packname[45] = 0;
+               snprintf(path, sizeof(path), "%s/pack/pack-%s.keep",
+                        get_object_directory(), packname + 5);
+               return xstrdup(path);
+       }
+       return NULL;
+}