Joerg Sonnenberger <joerg%britannica.bec.de@localhost> wrote:
> On Mon, Feb 27, 2012 at 09:30:47AM -0500, Jan Schaumann wrote:
> > It appears that at the moment pkg_add(1) requires the PKG_PATH variable
> > to not end in a /. However, it seems to me like a common user "mistake"
> > to include the trailing slash. The resulting error message is not
> > entirely unreasonable:
>
> Actually, it's more problematic. There are other cases like
> ftp://foo/bar//baz that will fail with the same. Your patch doesn't work
> either, since PKG_PATH can have more than one entry.
Ah, good point. Perhaps we could have process_pkg_path handle that? I
think I'd be hesitant to add duplicate slash detection, since that might
be a result of an unset environment variable and silently removing one
of those slashes might cover up such a mistake, but helping the user
with the trailing slash might still be worthwhile:
--- files/lib/pkg_io.c 20 Apr 2010 00:39:13 -0000 1.11
+++ files/lib/pkg_io.c 27 Feb 2012 14:46:35 -0000
@@ -281,7 +281,7 @@
int relative_path;
struct pkg_path *pl;
const char *start, *next;
- size_t len;
+ size_t len, pl_len;
if (getcwd(cwd, sizeof(cwd)) == NULL)
errx(EXIT_FAILURE, "getcwd failed");
@@ -301,6 +301,10 @@
pl->pl_path = xasprintf("%s%s%*.*s",
relative_path ? cwd : "", len && relative_path ? "/" : "",
(int)len, (int)len, start);
+ pl_len = strlen(pl->pl_path);
+ if (pl->pl_path[pl_len] == '/') {
+ pl->pl_path[pl_len] = '\0';
+ }
TAILQ_INSERT_TAIL(&pkg_path, pl, pl_link);
}
}
-Jan
Attachment:
pgpiNlxWKy86v.pgp
Description: PGP signature