summaryrefslogtreecommitdiff
path: root/lockfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/lockfile.c b/lockfile.c
index 828d19f..6851fa5 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -16,7 +16,7 @@ static void remove_lock_file(void)
lock_file_list->filename[0]) {
if (lock_file_list->fd >= 0)
close(lock_file_list->fd);
- unlink(lock_file_list->filename);
+ unlink_or_warn(lock_file_list->filename);
}
lock_file_list = lock_file_list->next;
}
@@ -155,18 +155,32 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
return lk->fd;
}
-
-NORETURN void unable_to_lock_index_die(const char *path, int err)
+static char *unable_to_lock_message(const char *path, int err)
{
+ struct strbuf buf = STRBUF_INIT;
+
if (err == EEXIST) {
- die("Unable to create '%s.lock': %s.\n\n"
+ strbuf_addf(&buf, "Unable to create '%s.lock': %s.\n\n"
"If no other git process is currently running, this probably means a\n"
"git process crashed in this repository earlier. Make sure no other git\n"
"process is running and remove the file manually to continue.",
path, strerror(err));
- } else {
- die("Unable to create '%s.lock': %s", path, strerror(err));
- }
+ } else
+ strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
+ return strbuf_detach(&buf, NULL);
+}
+
+int unable_to_lock_error(const char *path, int err)
+{
+ char *msg = unable_to_lock_message(path, err);
+ error("%s", msg);
+ free(msg);
+ return -1;
+}
+
+NORETURN void unable_to_lock_index_die(const char *path, int err)
+{
+ die("%s", unable_to_lock_message(path, err));
}
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
@@ -259,7 +273,7 @@ void rollback_lock_file(struct lock_file *lk)
if (lk->filename[0]) {
if (lk->fd >= 0)
close(lk->fd);
- unlink(lk->filename);
+ unlink_or_warn(lk->filename);
}
lk->filename[0] = 0;
}