aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index 827e543b0..bbcdc88e4 100644
--- a/refs.c
+++ b/refs.c
@@ -2530,12 +2530,14 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
static int rename_tmp_log(const char *newrefname)
{
+ int attempts_remaining = 3;
+
+ retry:
if (safe_create_leading_directories(git_path("logs/%s", newrefname))) {
error("unable to create directory for %s", newrefname);
return -1;
}
- retry:
if (rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
if (errno==EISDIR || errno==ENOTDIR) {
/*
@@ -2548,6 +2550,13 @@ static int rename_tmp_log(const char *newrefname)
return -1;
}
goto retry;
+ } else if (errno == ENOENT && --attempts_remaining > 0) {
+ /*
+ * Maybe another process just deleted one of
+ * the directories in the path to newrefname.
+ * Try again from the beginning.
+ */
+ goto retry;
} else {
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
newrefname, strerror(errno));