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>
This commit is contained in:
parent
8e86c155d2
commit
1b1648f46b
@ -318,8 +318,13 @@ int commit_lock_file(struct lock_file *lk)
|
|||||||
/* remove ".lock": */
|
/* remove ".lock": */
|
||||||
result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
|
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;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
lk->filename[0] = 0;
|
lk->filename[0] = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user