Skip to content

Commit

Permalink
rename_tmp_log(): limit the number of remote_empty_directories() atte…
Browse files Browse the repository at this point in the history
…mpts

This doesn't seem to be a likely error, but we've got the counter
anyway, so we might as well use it for an added bit of safety.

Please note that the first call to rename() is optimistic, and it is
normal for it to fail if there is a directory in the way.  So bump the
total number of allowed attempts to 4, to be sure that we can still
have at least 3 retries in the case of a race.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 21, 2014
1 parent ae4a283 commit f1e9e9a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)

static int rename_tmp_log(const char *newrefname)
{
int attempts_remaining = 3;
int attempts_remaining = 4;

retry:
if (safe_create_leading_directories(git_path("logs/%s", newrefname))) {
Expand All @@ -2539,7 +2539,7 @@ static int rename_tmp_log(const char *newrefname)
}

if (rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
if (errno==EISDIR || errno==ENOTDIR) {
if ((errno==EISDIR || errno==ENOTDIR) && --attempts_remaining > 0) {
/*
* rename(a, b) when b is an existing
* directory ought to result in ISDIR, but
Expand Down

0 comments on commit f1e9e9a

Please sign in to comment.