From owner-p4-projects@FreeBSD.ORG Sun Aug 1 13:11:28 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 69E5B1065677; Sun, 1 Aug 2010 13:11:28 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CE9F1065675 for ; Sun, 1 Aug 2010 13:11:28 +0000 (UTC) (envelope-from jlaffaye@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 19AC28FC12 for ; Sun, 1 Aug 2010 13:11:28 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id o71DBRfo093722 for ; Sun, 1 Aug 2010 13:11:28 GMT (envelope-from jlaffaye@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id o71DBRQa093720 for perforce@freebsd.org; Sun, 1 Aug 2010 13:11:27 GMT (envelope-from jlaffaye@FreeBSD.org) Date: Sun, 1 Aug 2010 13:11:27 GMT Message-Id: <201008011311.o71DBRQa093720@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jlaffaye@FreeBSD.org using -f From: Julien Laffaye To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181680 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Aug 2010 13:11:28 -0000 http://p4web.freebsd.org/@@181680?ac=10 Change 181680 by jlaffaye@jlaffaye-chulak on 2010/08/01 13:11:09 - Various cleanup - Remove references to PKG_ADD_BASE as it is not used - Use dirname(3) in find_package_url() Suggested-by: gcooper@ Affected files ... .. //depot/projects/soc2010/pkg_complete/lib/libpkg/url.c#7 edit .. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#12 edit Differences ... ==== //depot/projects/soc2010/pkg_complete/lib/libpkg/url.c#7 (text+ko) ==== @@ -23,8 +23,8 @@ #include #include -#include #include +#include #include #include #include /* NOTE: stdio must come before fetch. */ @@ -188,50 +188,41 @@ /* * Given a know-good URL `base', construct the URL to fetch `pkgname'. - * If the environment variable `PKG_ADD_BASE' (setted by sysinstall) exist, - * it is used to construct the URL ($PKG_ADD_BASE concatened with pkgname), - * and `base' is only used to find the file extension. - * The resulting URL string is stored at the memory of size FILENAME_MAX + * The resulting URL is stored in a fixed buffer of size MAXPATHLEN * pointed by `p'. * Returns 0 on success, 1 otherwise. */ int find_package_url(char * restrict p, const char *base, const char *pkgname) { - char *cp; + char *base_url; char *ext; - assert(p != NULL); - assert(base != NULL); - assert(pkgname != NULL); + if (p == NULL || base == NULL || pkgname == NULL) { + errno = EINVAL; + return (1); + } if ((ext = strrchr(base, '.')) == NULL) ext = ".tbz"; - /* Special tip that sysinstall left for us */ - if ((cp = getenv("PKG_ADD_BASE")) != NULL) { - strlcpy(p, cp, FILENAME_MAX); - strlcat(p, pkgname, FILENAME_MAX); - strlcat(p, ext, FILENAME_MAX); - } else { - strlcpy(p, base, FILENAME_MAX); - /* - * Advance back two slashes to get to the root of the - * package hierarchy, then append pkgname. - */ - cp = strrchr(p, '/'); - if (cp != NULL) { - *cp = '\0'; /* chop name */ - cp = strrchr(p, '/'); - } - if (cp != NULL) { - *(cp + 1) = '\0'; - strlcat(p, "All/", FILENAME_MAX); - strlcat(p, pkgname, FILENAME_MAX); - strlcat(p, ext, FILENAME_MAX); - } else - return (1); + /* + * Advance back two directories to get to the root of the + * package hierarchy, then append pkgname. + */ + if ((base_url = dirname(base)) == NULL) { + warn("dirname()"); + return (1); + } + if ((base_url = dirname(base_url)) == NULL) { + warn("dirname()"); + return (1); + } + if (!isURL(base_url)) { + warnx("%s(): The URL found '%s' is not valid!", __func__, base_url); + return (1); } + snprintf(p, MAXPATHLEN, "%s/All/%s%s", base_url, pkgname, ext); return (0); } @@ -255,7 +246,8 @@ int percent; if (!isURL(url)) { - warnx("fetch_archive(): '%s' is not an URL!", url); + warnx("%s(): '%s' is not a known URL!", __func__, url); + errno = EINVAL; return (-1); } ==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#12 (text+ko) ==== @@ -222,7 +222,7 @@ if (PrefixRecursive == FALSE) Prefix = NULL; - if (!isURL(fname) && !getenv("PKG_ADD_BASE")) { + if (!isURL(fname)) { const char *ext; ext = strrchr(fname, '.'); @@ -254,7 +254,7 @@ } } else { - char dep_url[FILENAME_MAX]; + char dep_url[MAXPATHLEN]; if (find_package_url(dep_url, fname, p->name) != 0) errx(1, "Can not make an URL to get %s", p->name);