lockfile: unlock file if lockfile permissions cannot be adjusted
[gitweb.git] / lockfile.c
index e55149a73ac05298861f8820945b89200da5f177..d74de8d329a4adc3e9c2b158365292c36a37a10d 100644 (file)
@@ -153,6 +153,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
                        int save_errno = errno;
                        error("cannot fix permission bits on %s",
                              lk->filename);
+                       rollback_lock_file(lk);
                        errno = save_errno;
                        return -1;
                }
@@ -279,8 +280,7 @@ void rollback_lock_file(struct lock_file *lk)
        if (!lk->filename[0])
                return;
 
-       if (lk->fd >= 0)
-               close(lk->fd);
+       close_lock_file(lk);
        unlink_or_warn(lk->filename);
        lk->filename[0] = 0;
 }