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>
Peter Collingbourne committed
Mar 26, 2010 at 15:25 UTC
10e13ec8ed36019d131d27cd9fe2e8cc0f99b896
1 file changed
+7
-5
wrapper.c
+7
-5
@@ -311,18 +311,20 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
311
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
312
}
313
314
-int unlink_or_warn(const char *file)
314
+static int warn_if_unremovable(const char *op, const char *file, int rc)
315
{
316
- int rc = unlink(file);
317
-
316
if (rc < 0) {
317
int err = errno;
318
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));
321
errno = err;
322
}
323
}
324
return rc;
325
}
326
327
+int unlink_or_warn(const char *file)
328
+{
329
+ return warn_if_unremovable("unlink", file, unlink(file));
330
+}