summaryrefslogtreecommitdiff
path: root/lockfile.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 12:28:23 +0200
committerJunio C Hamano <gitster@pobox.com>2014-10-01 13:45:14 -0700
commit1b1648f46bcb638f558e9cbd2d0e89066c89c44e (patch)
tree47a9ea458b4b3a3f460ddacf79934fe88c016ebd /lockfile.c
parent8e86c155d2962f5dff83c9d0d88b836bf040c1fa (diff)
downloadgit-1b1648f46bcb638f558e9cbd2d0e89066c89c44e.tar.gz
commit_lock_file(): rollback lock file on failure to rename
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>
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lockfile.c b/lockfile.c
index 1d18c67ea8..728ce49765 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -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;
}