introduce got_error_path()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/got/got.c b/got/got.c
index 30aca9d..46b3ebb 100644
--- a/got/got.c
+++ b/got/got.c
@@ -226,7 +226,6 @@ apply_unveil(const char *repo_path, int repo_read_only,
const char *worktree_path, int create_worktree)
{
const struct got_error *err;
- static char err_msg[MAXPATHLEN + 36];
if (create_worktree) {
/* Pre-create work tree path to avoid unveiling its parents. */
@@ -237,11 +236,8 @@ apply_unveil(const char *repo_path, int repo_read_only,
errno = 0;
err = NULL;
} else {
- snprintf(err_msg, sizeof(err_msg),
- "%s: directory exists and is not empty",
- worktree_path);
- err = got_error_msg(GOT_ERR_DIR_NOT_EMPTY,
- err_msg);
+ err = got_error_path(worktree_path,
+ GOT_ERR_DIR_NOT_EMPTY);
}
}
diff --git a/include/got_error.h b/include/got_error.h
index 5672559..b5b08b3 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -247,3 +247,6 @@ const struct got_error *got_error_not_ref(const char *);
/* Return an error based on a uuid(3) status code. */
const struct got_error *got_error_uuid(uint32_t);
+
+/* Return an error with a path prefixed to the error message. */
+const struct got_error *got_error_path(const char *, int);
diff --git a/lib/error.c b/lib/error.c
index c3af78d..bb7df07 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -172,3 +172,23 @@ got_error_uuid(uint32_t uuid_status)
return got_error(GOT_ERR_UUID);
}
}
+
+const struct got_error *
+got_error_path(const char *path, int code)
+{
+ static struct got_error err;
+ static char msg[MAXPATHLEN + 128];
+ int i;
+
+ for (i = 0; i < nitems(got_errors); i++) {
+ if (code == got_errors[i].code) {
+ err.code = code;
+ snprintf(msg, sizeof(msg), "%s: %s", path,
+ got_errors[i].msg);
+ err.msg = msg;
+ return &err;
+ }
+ }
+
+ abort();
+}