PERFORCE change 177907 for review

Garrett Cooper gcooper at FreeBSD.org
Fri May 7 15:00:45 UTC 2010


http://p4web.freebsd.org/@@177907?ac=10

Change 177907 by gcooper at gcooper-bayonetta on 2010/05/07 14:59:48

	1. Check for the results when initializing the compressor better.
	2. Consolidate warnx(3) calls so that it'll be easier to remove them
	   all in one fell swoop and replace the code with
	   equivalent/compatible libcalls.
	3. Remove an unused var and improve the return behavior for
	   unpack_from_fd.

Affected files ...

.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#6 edit

Differences ...

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#6 (text+ko) ====

@@ -390,31 +390,25 @@
 
 	if ((archive = archive_read_new()) != NULL) {
 
-		archive_read_support_compression_all(archive);
-		archive_read_support_format_tar(archive);
-
+		if (archive_read_support_compression_all(archive)
+		    != ARCHIVE_OK ||
+		    archive_read_support_format_tar(archive) != ARCHIVE_OK)
+			error = archive_error_string(archive);
 		/*
 		 * Avoid potential race conditions with
 		 * archive_read_open_filename(3), by opening the file
 		 * beforehand.
 		 */
-		if (pkg == NULL)
+		else if (pkg == NULL)
 			archive_fd = fileno(stdin);
 		else
 			archive_fd = open(pkg, O_RDONLY);
 
 	}
 
-	if (archive == NULL) {
-		error = archive_error_string(archive);
-		warnx("%s: unable to open the package from %s: %s",
-		    __func__, pkg_name_humanized, error);
-	}
-	/* The initial open failed */
-	else if (archive_fd == -1)
-		warn("%s: unable to open the package from %s",
-		    __func__, pkg_name_humanized);
-	/* archive(3) failed to open the file. */
+	/* The initial open failed or archive(3) failed to open the file. */
+	if (archive_fd != -1 || archive == NULL) ;
+	/* archive(3) failed to open the file descriptor. */
 	else if (archive_read_open_fd(archive, archive_fd,
 	    ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
 		error = archive_error_string(archive);
@@ -458,6 +452,11 @@
 
 		}
 
+	if (errno != 0)
+		error = strerror(errno);
+	if (error != NULL)
+		warnx("%s: unable to read the file - %s - from package: %s: "
+		    "%s", __func__, file, pkg_name_humanized, error);
 
 	if (archive != NULL)
 		archive_read_finish(archive);
@@ -486,7 +485,7 @@
 	const char *entry_pathname = NULL;
 	const char *error = NULL;
 	const char *pkg_name_humanized;
-	int archive_fd = -1, r, serrno;
+	int archive_fd = -1, r;
 
 	if (file_expr == NULL || strcmp("*", file_expr) == 0)
 		extract_whole_archive = TRUE;
@@ -508,30 +507,25 @@
 
 	if ((archive = archive_read_new()) != NULL) {
 
-		archive_read_support_compression_all(archive);
-		archive_read_support_format_tar(archive);
-
+		if (archive_read_support_compression_all(archive)
+		    != ARCHIVE_OK ||
+		    archive_read_support_format_tar(archive) != ARCHIVE_OK)
+			error = archive_error_string(archive);
 		/*
 		 * Avoid potential race conditions with
 		 * archive_read_open_filename(3), by opening the file
 		 * beforehand.
 		 */
-		if (pkg == NULL)
+		else if (pkg == NULL)
 			archive_fd = fileno(stdin);
 		else
 			archive_fd = open(pkg, O_RDONLY);
 
 	}
 
-	if (archive == NULL) {
-		error = archive_error_string(archive);
-		warnx("%s: unable to open the package from %s: %s",
-		    __func__, pkg_name_humanized, error);
-	}
-	/* The initial open failed */
-	else if (archive_fd == -1)
-		warn("%s: unable to open the package from %s",
-		    __func__, pkg_name_humanized);
+	/* The initial open failed or archive(3) failed to open the file. */
+	if (archive_fd != -1 || archive == NULL) ;
+	/* archive(3) failed to open the file descriptor. */
 	else if (archive_read_open_fd(archive, archive_fd,
 	    ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
 
@@ -571,14 +565,19 @@
 
 		}
 
-	serrno = errno;
+	if (errno != 0)
+		error = strerror(errno);
+	if (error != NULL)
+		warnx("%s: unpacking package - %s - failed: %s",
+		    __func__, pkg_name_humanized, error);
+
 	if (archive != NULL)
 		archive_read_finish(archive);
 	/* Close any open descriptors. */
 	if (0 <= archive_fd)
 		close(archive_fd);
 
-	return (error == NULL && errno == 0 ? 0 : 1);
+	return (error == NULL ? 0 : 1);
 
 }
 


More information about the p4-projects mailing list