From owner-p4-projects@FreeBSD.ORG Fri May 7 15:00:44 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BEF711065676; Fri, 7 May 2010 15:00:44 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6B5C61065674 for ; Fri, 7 May 2010 15:00:44 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 50E248FC12 for ; Fri, 7 May 2010 15:00:44 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o47F0i8q018822 for ; Fri, 7 May 2010 15:00:44 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o47F0iKt018820 for perforce@freebsd.org; Fri, 7 May 2010 15:00:44 GMT (envelope-from gcooper@FreeBSD.org) Date: Fri, 7 May 2010 15:00:44 GMT Message-Id: <201005071500.o47F0iKt018820@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 177907 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: Fri, 07 May 2010 15:00:45 -0000 http://p4web.freebsd.org/@@177907?ac=10 Change 177907 by gcooper@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); }