]> git.ipfire.org Git - thirdparty/git.git/commit - lockfile.c
close_lock_file(): if close fails, roll back
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:22 +0000 (12:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2014 20:45:13 +0000 (13:45 -0700)
commit8e86c155d2962f5dff83c9d0d88b836bf040c1fa
tree6b9eef5ab880a3249cdb4cab59a19d19ee3049fc
parent8a1c7533e2ee468a505656abab364780b15004fc
close_lock_file(): if close fails, roll back

If closing an open lockfile fails, then we cannot be sure of the
contents of the lockfile, so there is nothing sensible to do but
delete it. This change also insures that the lock_file object is left
in a defined state in this error path (namely, unlocked).

The only caller that is ultimately affected by this change is
try_merge_strategy() -> write_locked_index(), which can call
close_lock_file() via various execution paths. This caller uses a
static lock_file object which previously could have been reused after
a failed close_lock_file() even though it was still in locked state.
This change causes the lock_file object to be unlocked on failure,
thus fixing this error-handling path.

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