summaryrefslogtreecommitdiff
path: root/wrapper.c
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-07-16 11:20:36 -0700
committerJunio C Hamano <gitster@pobox.com>2014-10-15 10:47:21 -0700
commit9ccc0c089667e6dccc888590376f138521784e5e (patch)
treef51130e16fe3945b137f76ac5862a917ec45d6a9 /wrapper.c
parent3c93c847cacea68e520f6099b18c69f406ab9407 (diff)
downloadgit-9ccc0c089667e6dccc888590376f138521784e5e.tar.gz
wrapper.c: add a new function unlink_or_msg
This behaves like unlink_or_warn except that on failure it writes the message to its 'err' argument, which the caller can display in an appropriate way or ignore. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/wrapper.c b/wrapper.c
index 8d4be66e66..007ec0d8ea 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -475,6 +475,20 @@ static int warn_if_unremovable(const char *op, const char *file, int rc)
return rc;
}
+int unlink_or_msg(const char *file, struct strbuf *err)
+{
+ int rc = unlink(file);
+
+ assert(err);
+
+ if (!rc || errno == ENOENT)
+ return 0;
+
+ strbuf_addf(err, "unable to unlink %s: %s",
+ file, strerror(errno));
+ return -1;
+}
+
int unlink_or_warn(const char *file)
{
return warn_if_unremovable("unlink", file, unlink(file));