]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit_lock_file(): rollback lock file on failure to rename
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:23 +0000 (12:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2014 20:45:14 +0000 (13:45 -0700)
If rename() fails, call rollback_lock_file() to delete the lock file
(in case it is still present) and reset the filename field to the
empty string so that the lockfile object is left in a valid state.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c

index 1d18c67ea8d86df9bca2c567763834ac80704622..728ce497654127ce7245f34c894b3ef8db92fa74 100644 (file)
@@ -318,8 +318,13 @@ int commit_lock_file(struct lock_file *lk)
        /* remove ".lock": */
        result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
 
-       if (rename(lk->filename, result_file))
+       if (rename(lk->filename, result_file)) {
+               int save_errno = errno;
+               rollback_lock_file(lk);
+               errno = save_errno;
                return -1;
+       }
+
        lk->filename[0] = 0;
        return 0;
 }