diff options
author | Jeff King <peff@peff.net> | 2015-12-29 00:57:25 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-12-29 10:34:25 -0800 |
commit | 396da8f7a07ae02a6152e0c0fc3eaac8a99b4c65 (patch) | |
tree | d05f7f3e507ade3fcbc1722e2f6af772d31ec498 /refs | |
parent | 370e5ad65e8878989eecbae28a479b1a4d6a841b (diff) | |
download | git-396da8f7a07ae02a6152e0c0fc3eaac8a99b4c65.tar.gz git-396da8f7a07ae02a6152e0c0fc3eaac8a99b4c65.tar.xz |
create_symref: write reflog while holding lock
We generally hold a lock on the matching ref while writing
to its reflog; this prevents two simultaneous writers from
clobbering each other's reflog lines (it does not even have
to be two symref updates; because we don't hold the lock, we
could race with somebody writing to the pointed-to ref via
HEAD, for example).
We can fix this by writing the reflog before we commit the
lockfile. This runs the risk of writing the reflog but
failing the final rename(), but at least we now err on the
same side as the rest of the ref code.
Noticed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r-- | refs/files-backend.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index 3d1994deb..180c837d1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2850,12 +2850,13 @@ static int create_symref_locked(struct ref_lock *lock, const char *refname, return error("unable to fdopen %s: %s", lock->lk->tempfile.filename.buf, strerror(errno)); + update_symref_reflog(lock, refname, target, logmsg); + /* no error check; commit_ref will check ferror */ fprintf(lock->lk->tempfile.fp, "ref: %s\n", target); if (commit_ref(lock) < 0) return error("unable to write symref for %s: %s", refname, strerror(errno)); - update_symref_reflog(lock, refname, target, logmsg); return 0; } |