Merge branch 'da/include-compat-util-first-in-c'
[gitweb.git] / lockfile.c
index 2564a7f5447b904585f629f0d1233c8a59483a40..d34a96df4f859feeaa7597abba374128ff9dc598 100644 (file)
@@ -224,8 +224,11 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
        } else if (copy_fd(orig_fd, fd)) {
                if (flags & LOCK_DIE_ON_ERROR)
                        exit(128);
+               close(orig_fd);
                close(fd);
                return -1;
+       } else {
+               close(orig_fd);
        }
        return fd;
 }
@@ -237,6 +240,16 @@ int close_lock_file(struct lock_file *lk)
        return close(fd);
 }
 
+int reopen_lock_file(struct lock_file *lk)
+{
+       if (0 <= lk->fd)
+               die(_("BUG: reopen a lockfile that is still open"));
+       if (!lk->filename[0])
+               die(_("BUG: reopen a lockfile that has been committed"));
+       lk->fd = open(lk->filename, O_WRONLY);
+       return lk->fd;
+}
+
 int commit_lock_file(struct lock_file *lk)
 {
        char result_file[PATH_MAX];