Date: Sat, 24 Mar 2001 01:50:00 +0200 (EET) From: Maxim Sobolev <sobomax@freebsd.org> To: rooneg@electricjellyfish.net (Garrett Rooney) Cc: jkh@osd.bsdi.com (Jordan Hubbard), sobomax@freebsd.org, ports@freebsd.org Subject: Re: cvs commit: src/usr.sbin/pkg_install/info info.h main.c perform.c pkg_info.1 show.c src/usr.sbin/pkg_install/lib depOR Message-ID: <200103232350.f2NNo5H01267@vic.sabbo.net> In-Reply-To: <20010323173301.A52371@electricjellyfish.net> from "Garrett Rooney" at Mar 23, 2001 05:33:01 PM
next in thread | previous in thread | raw e-mail | index | archive | help
> > On Fri, Mar 23, 2001 at 02:25:55PM -0800, Jordan Hubbard wrote: > > What did you end up doing about the realpath() issue? Just > > curious. > > the patch as committed doesn't use realpath at all. it isn't quite as smart > about relative paths as a result, but it will deal with simple cases. > > (ie, if you're in /usr/X11R6 you can run 'pkg_info -W bin/sawfish' and it'll > work, but if you give it something more compilcated, with ..'s or .'s or > multiple slashes it'll fail.) > > it also allows you to just specify an executable, and if it can't find it in > the current dir (which would indicate you were trying a relative path), it'll > use which(1) to get a path to search for. > > so it's fairly smart, without using realpath. ideally, i was thinking of > writing some code to deal with the more complicated cases, but real life got > in the way. how often will someone want to say 'pkg_info -W ../.././/foo' > anyway? Following piece of code should solve this problem. It basically does what the realpath(3) does, but doesn't try to resolve symlinks, which as far as I unrestood is the main problem here. Actually it could be modified to take two components (cwd and relative pathname), so we will handle ../ and ./ in PLISTS properly. -Maxim P.S. I intentionally did not clutter code with alloc errors checking. It could be done later. ----- cut here ----- char * unrealpath(const char *pathname) { char *cwd, *tmp, *tmp1; char *resolved_path; int len; if (pathname[0] != '/') { cwd = getcwd(NULL, MAXPATHLEN); asprintf(&resolved_path, "%s/%s/", cwd, pathname); free(cwd); } else asprintf(&resolved_path, "%s/", pathname); while ((tmp = strstr(resolved_path, "//")) != NULL) strcpy(tmp, tmp + 1); while ((tmp = strstr(resolved_path, "/./")) != NULL) strcpy(tmp, tmp + 2); while ((tmp = strstr(resolved_path, "/../")) != NULL) { *tmp = '\0'; if ((tmp1 = strrchr(resolved_path, '/')) == NULL) tmp1 = resolved_path; strcpy(tmp1, tmp + 3); } len = strlen(resolved_path); if (len > 1 && resolved_path[len - 1] == '/') resolved_path[len - 1] = '\0'; return resolved_path; } ---- cut here ---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103232350.f2NNo5H01267>