Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 May 2010 07:20:26 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 178027 for review
Message-ID:  <201005100720.o4A7KQiO046666@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178027?ac=10

Change 178027 by gcooper@gcooper-bayonetta on 2010/05/10 07:20:24

	
	Update some comments, group the prefix == NULL functionality together
	better, convert some callocs to mallocs, and fix @srcdir.

Affected files ...

.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#10 edit

Differences ...

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#10 (text+ko) ====

@@ -406,11 +406,15 @@
 	if (Regenerate == FALSE)
 		archive_open_flags |= O_CREAT;
 
-	if ((destfile = calloc(PATH_MAX, sizeof(char))) == NULL ||
+	/* 
+	 * NOTE (gcooper): No sense in calloc'ing destfile or srcfile as the
+	 * first byte is zeroed out below in the archive add loop.
+	 */
+	if ((destfile = malloc(PATH_MAX, sizeof(char))) == NULL ||
 	   (destbase = calloc(PATH_MAX, sizeof(char))) == NULL ||
 	   (prefix = calloc(PATH_MAX, sizeof(char))) == NULL ||
 	   (srcbase = calloc(PATH_MAX, sizeof(char))) == NULL ||
-	   (srcfile = calloc(PATH_MAX, sizeof(char))) == NULL)
+	   (srcfile = malloc(PATH_MAX, sizeof(char))) == NULL)
 		error = strerror(errno);
 	/*
 	 * If the package tarball exists already, and we are running in
@@ -513,6 +517,10 @@
 
 			destfile[0] = srcfile[0] = '\0';
 
+			/*
+			 * File is based off the current working directory if
+			 * NULL.
+			 */
 			if (destbase != NULL)
 				if (strlcat(destfile, destbase, PATH_MAX) >
 				    PATH_MAX)
@@ -539,6 +547,7 @@
 
 		case PLIST_CWD:
 
+			/* Reset to <prefix>/<basedir> */
 			if (p->name == NULL) {
 				/*
 				 * Broken plist; prefix must be defined before
@@ -553,22 +562,39 @@
 					error = strerror(ENAMETOOLONG);
 
 				/* Reset srcbase */
-				if (strlcpy(srcbase, BaseDir, PATH_MAX) >
-				    PATH_MAX)
-					error = strerror(ENAMETOOLONG);
-				else if (strlcpy(srcbase, prefix, PATH_MAX) >
-				    PATH_MAX)
-					error = strerror(ENAMETOOLONG);
-
-			} else {
-
 				/* Tack BaseDir on the front if defined. */
 				if (BaseDir != NULL) {
 					if (strlcpy(srcbase, BaseDir,
 					    PATH_MAX) > PATH_MAX)
 						error = strerror(ENAMETOOLONG);
-				} else
-					srcbase[0] = '\0';
+				if (strlcpy(srcbase, prefix, PATH_MAX) >
+				    PATH_MAX)
+					error = strerror(ENAMETOOLONG);
+
+			}
+			/*
+			 * 1. Accumulate the directory argument. or
+			 * 2. Set the prefix as this is the first @cwd.
+			 */
+			else {
+
+				/* First @cwd -- wewt! */
+				if (prefix == NULL) {
+
+					prefix = p->name;
+
+				 	/*
+					 * Tack BaseDir on the front if
+					 * defined and this is the first run.
+					 */
+					if (BaseDir != NULL) {
+						if (strlcpy(srcbase, BaseDir,
+						    PATH_MAX) > PATH_MAX)
+							error = strerror(ENAMETOOLONG);
+					} else
+						srcbase[0] = '\0';
+
+				}
 
 				if (strlcat(destbase, p->name, PATH_MAX) >
 				    PATH_MAX)
@@ -578,10 +604,6 @@
 				    PATH_MAX)
 					error = strerror(ENAMETOOLONG);
 
-				/* First @cwd statement. */
-				if (prefix == NULL)
-					prefix = p->name;
-
 			}
 
 			/* 
@@ -623,12 +645,10 @@
 			assert(p->name != NULL);
 
 			/* 
-			 * Set the appropriate prefix for the next file to
-			 * install (only for @srcdir).
-			 *
-			 * Reset to ''
+			 * Set the appropriate prefix for the next `@cwd'
+			 * call.
 			 */
-			if (strlcpy(srcbase, p->name, PATH_MAX) >
+			if (strlcpy(prefix, p->name, PATH_MAX) >
 			    PATH_MAX)
 				error = strerror(ENAMETOOLONG);
 



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