Skip to content

Commit 10e13ec

Browse files
pccgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e4f614 commit 10e13ec

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

wrapper.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,20 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
311311
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
312312
}
313313

314-
int unlink_or_warn(const char *file)
314+
static int warn_if_unremovable(const char *op, const char *file, int rc)
315315
{
316-
int rc = unlink(file);
317-
318316
if (rc < 0) {
319317
int err = errno;
320318
if (ENOENT != err) {
321-
warning("unable to unlink %s: %s",
322-
file, strerror(errno));
319+
warning("unable to %s %s: %s",
320+
op, file, strerror(errno));
323321
errno = err;
324322
}
325323
}
326324
return rc;
327325
}
328326

327+
int unlink_or_warn(const char *file)
328+
{
329+
return warn_if_unremovable("unlink", file, unlink(file));
330+
}

0 commit comments

Comments
 (0)