diff --git a/git-compat-util.h b/git-compat-util.h index fb41118c07..d67592fd96 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -777,11 +777,14 @@ void git_qsort(void *base, size_t nmemb, size_t size, /* * Preserves errno, prints a message, but gives no warning for ENOENT. - * Always returns the return value of unlink(2). + * Returns 0 on success, which includes trying to unlink an object that does + * not exist. */ int unlink_or_warn(const char *path); /* - * Likewise for rmdir(2). + * Preserves errno, prints a message, but gives no warning for ENOENT. + * Returns 0 on success, which includes trying to remove a directory that does + * not exist. */ int rmdir_or_warn(const char *path); /* diff --git a/refs.c b/refs.c index a77458f2f6..2dcf6c6e03 100644 --- a/refs.c +++ b/refs.c @@ -2607,7 +2607,7 @@ static int delete_ref_loose(struct ref_lock *lock, int flag) char *loose_filename = get_locked_file_path(lock->lk); int err = unlink_or_warn(loose_filename); free(loose_filename); - if (err && errno != ENOENT) + if (err) return 1; } return 0; diff --git a/wrapper.c b/wrapper.c index 5b77d2a1ae..8d4be66e66 100644 --- a/wrapper.c +++ b/wrapper.c @@ -466,14 +466,12 @@ int xmkstemp_mode(char *template, int mode) static int warn_if_unremovable(const char *op, const char *file, int rc) { - if (rc < 0) { - int err = errno; - if (ENOENT != err) { - warning("unable to %s %s: %s", - op, file, strerror(errno)); - errno = err; - } - } + int err; + if (!rc || errno == ENOENT) + return 0; + err = errno; + warning("unable to %s %s: %s", op, file, strerror(errno)); + errno = err; return rc; }