From owner-freebsd-ports Fri Mar 23 15:50:31 2001 Delivered-To: freebsd-ports@freebsd.org Received: from blizzard.sabbo.net (ns.sabbo.net [193.193.218.18]) by hub.freebsd.org (Postfix) with ESMTP id 8613637B719; Fri, 23 Mar 2001 15:50:18 -0800 (PST) (envelope-from max@vic.sabbo.net) Received: from vic.sabbo.net (root@vic.sabbo.net [193.193.218.112]) by blizzard.sabbo.net (8.10.1/8.10.1) with ESMTP id f2NNo6X15135; Sat, 24 Mar 2001 01:50:08 +0200 Received: (from max@localhost) by vic.sabbo.net (8.11.3/8.11.2) id f2NNo5H01267; Sat, 24 Mar 2001 01:50:05 +0200 (EET) (envelope-from sobomax@FreeBSD.org) From: Maxim Sobolev Message-Id: <200103232350.f2NNo5H01267@vic.sabbo.net> 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 To: rooneg@electricjellyfish.net (Garrett Rooney) Date: Sat, 24 Mar 2001 01:50:00 +0200 (EET) Cc: jkh@osd.bsdi.com (Jordan Hubbard), sobomax@freebsd.org, ports@freebsd.org In-Reply-To: <20010323173301.A52371@electricjellyfish.net> from "Garrett Rooney" at Mar 23, 2001 05:33:01 PM X-Mailer: ELM [version 2.5 PL5] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > > 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