Generalise the unlink_or_warn function

This patch moves the warning code of the unlink_or_warn function into
a separate function named warn_if_unremovable so that it may be reused.

Signed-off-by: Peter Collingbourne <peter@pcc.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Peter Collingbourne 2010-03-26 15:25:32 +00:00 committed by Junio C Hamano
parent 5e4f614742
commit 10e13ec8ed

View File

@ -311,18 +311,20 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
} }
int unlink_or_warn(const char *file) static int warn_if_unremovable(const char *op, const char *file, int rc)
{ {
int rc = unlink(file);
if (rc < 0) { if (rc < 0) {
int err = errno; int err = errno;
if (ENOENT != err) { if (ENOENT != err) {
warning("unable to unlink %s: %s", warning("unable to %s %s: %s",
file, strerror(errno)); op, file, strerror(errno));
errno = err; errno = err;
} }
} }
return rc; return rc;
} }
int unlink_or_warn(const char *file)
{
return warn_if_unremovable("unlink", file, unlink(file));
}