Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Aug 2010 13:11:27 GMT
From:      Julien Laffaye <jlaffaye@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 181680 for review
Message-ID:  <201008011311.o71DBRQa093720@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/param.h>
 #include <sys/wait.h>
-#include <assert.h>
 #include <err.h>
+#include <errno.h>
 #include <libgen.h>
 #include <stdio.h>
 #include <fetch.h>	/* 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008011311.o71DBRQa093720>