Commit 63f810e6fee43e699585195a24eebdb53a99a4f4

Stefan Sperling 2020-02-29T07:54:55

when "bad path" errors occur, always show the path in question

diff --git a/lib/object.c b/lib/object.c
index 174d3ab..f8ccc9e 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -152,7 +152,7 @@ get_packfile_path(char **path_packfile, struct got_packidx *packidx)
 	/* Packfile path contains ".pack" instead of ".idx", so add one byte. */
 	size = strlen(packidx->path_packidx) + 2;
 	if (size < GOT_PACKFILE_NAMELEN + 1)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(packidx->path_packidx, GOT_ERR_BAD_PATH);
 
 	*path_packfile = malloc(size);
 	if (*path_packfile == NULL)
@@ -1643,7 +1643,7 @@ got_object_tree_path_changed(int *changed,
 
 	/* We not do support comparing the root path. */
 	if (path[1] == '\0')
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	tree1 = tree01;
 	tree2 = tree02;
diff --git a/lib/path.c b/lib/path.c
index 612f8ea..01ae02e 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -112,11 +112,11 @@ got_path_skip_common_ancestor(char **child, const char *parent_abspath,
 	len_parent = strlen(parent_abspath);
 	len = strlen(abspath);
 	if (len_parent >= len)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(abspath, GOT_ERR_BAD_PATH);
 	if (strncmp(parent_abspath, abspath, len_parent) != 0)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(abspath, GOT_ERR_BAD_PATH);
 	if (!got_path_is_root_dir(parent_abspath) && abspath[len_parent] != '/')
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(abspath, GOT_ERR_BAD_PATH);
 	while (abspath[len_parent] == '/')
 		abspath++;
 	bufsize = len - len_parent + 1;
@@ -363,7 +363,7 @@ got_path_dirname(char **parent, const char *path)
 		return got_error_from_errno2("dirname", path);
 
 	if (p[0] == '.' && p[1] == '\0')
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	*parent = strdup(p);
 	if (*parent == NULL)
diff --git a/lib/repository.c b/lib/repository.c
index 479f6f6..1b376cc 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -543,7 +543,7 @@ got_repo_open(struct got_repository **repop, const char *path,
 	else
 		abspath = got_path_get_absolute(path);
 	if (abspath == NULL)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	repo = calloc(1, sizeof(*repo));
 	if (repo == NULL) {
diff --git a/lib/worktree.c b/lib/worktree.c
index 86333ed..0e0bef7 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2833,7 +2833,7 @@ got_worktree_resolve_path(char **wt_path, struct got_worktree *worktree,
 
 	if (strncmp(got_worktree_get_root_path(worktree), resolved,
 	    strlen(got_worktree_get_root_path(worktree)))) {
-		err = got_error(GOT_ERR_BAD_PATH);
+		err = got_error_path(resolved, GOT_ERR_BAD_PATH);
 		goto done;
 	}
 
@@ -2996,7 +2996,7 @@ schedule_for_deletion(void *arg, unsigned char status,
 
 	ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
 	if (ie == NULL)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(relpath, GOT_ERR_BAD_PATH);
 
 	staged_status = get_staged_status(ie);
 	if (staged_status != GOT_STATUS_NO_CHANGE) {
@@ -3465,7 +3465,7 @@ revert_file(void *arg, unsigned char status, unsigned char staged_status,
 
 	ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
 	if (ie == NULL)
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(relpath, GOT_ERR_BAD_PATH);
 
 	/* Construct in-repository path of tree which contains this blob. */
 	err = got_path_dirname(&parent_path, ie->path);
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index 4913359..37bda9d 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -452,7 +452,7 @@ tree_path_changed(int *changed, uint8_t **buf1, uint8_t **buf2,
 
 	/* We not do support comparing the root path. */
 	if (path[1] == '\0')
-		return got_error(GOT_ERR_BAD_PATH);
+		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	s = path;
 	s++; /* skip leading '/' */