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>
Michael Haggerty committed
Oct 1, 2014 at 12:28 UTC
1b1648f46bcb638f558e9cbd2d0e89066c89c44e
1 file changed
+6
-1
lockfile.c
+6
-1
@@ -318,8 +318,13 @@ int commit_lock_file(struct lock_file *lk)
318
/* remove ".lock": */
319
result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
320
321
- if (rename(lk->filename, result_file))
321
+ if (rename(lk->filename, result_file)) {
322
+ int save_errno = errno;
323
+ rollback_lock_file(lk);
324
+ errno = save_errno;
325
return -1;
326
+ }
327
+
328
lk->filename[0] = 0;
329
return 0;
330
}