commit df056ada35bdbbcc6e248b7ec0ec8a7d25fd5147 from: Stefan Sperling date: Wed May 15 11:27:06 2019 UTC introduce got_error_path() commit - b28fe61a139ab486d8098a954625482ba59b7056 commit + df056ada35bdbbcc6e248b7ec0ec8a7d25fd5147 blob - 30aca9d441b8c5cec4e3c2d3e766988bc110ef50 blob + 46b3ebb730cfbdd351180ada209da9dc4db793a5 --- got/got.c +++ 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); } } blob - 5672559ee3178f5472a06792f3793a49d8630d16 blob + b5b08b3be35c11bb53ff35ff3b1e4a100430c622 --- include/got_error.h +++ 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); blob - c3af78d19c9dcfb46c349c76e439e211bbcbe37f blob + bb7df07d0d94f6bb7c602257d3599b5056251f3b --- lib/error.c +++ 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(); +}