Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Apr 2012 20:57:37 -0400 (EDT)
From:      Steve Wills <steve@mouf.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/166895: add partial zipinfo mode support to base unzip
Message-ID:  <201204130057.q3D0vb80033086@meatwad.mouf.net>
Resent-Message-ID: <201204130100.q3D10Rje076410@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         166895
>Category:       bin
>Synopsis:       add partial zipinfo mode support to base unzip
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 13 01:00:26 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Steve Wills
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
>Environment:
System: FreeBSD meatwad.mouf.net 10.0-CURRENT FreeBSD 10.0-CURRENT #17 r233932: Thu Apr 5 22:13:25 EDT 2012 root@meatwad.mouf.net:/usr/obj/usr/src/sys/MEATWAD amd64

>Description:

	here's a patch I wrote to partiall implement zipinfo (-Z) support for
        the base unzip. This fixes some test failures seen with perl 5.12 and
        5.14.

>How-To-Repeat:

	install perl 5.12 or 5.14 on 9.x or 10.x and run "make test". Some
	tests related to Archive::Extract will fail due to trying to call
        unzip -Z -1 filename.  This patch makes that work.

>Fix:


Index: unzip.c
===================================================================
--- unzip.c	(revision 234193)
+++ unzip.c	(working copy)
@@ -65,6 +65,7 @@
 static int		 t_opt;		/* test */
 static int		 u_opt;		/* update */
 static int		 v_opt;		/* verbose/list */
+static int		 Z1_opt;	/* zipinfo mode list files only */
 
 /* time when unzip started */
 static time_t		 now;
@@ -72,6 +73,9 @@
 /* debug flag */
 static int		 unzip_debug;
 
+/* zipinfo mode */
+static int		 zipinfo_mode;
+
 /* running on tty? */
 static int		 tty;
 
@@ -802,17 +806,22 @@
 	mtime = archive_entry_mtime(e);
 	strftime(buf, sizeof(buf), "%m-%d-%g %R", localtime(&mtime));
 
-	if (v_opt == 1) {
-		printf(" %8ju  %s   %s\n",
-		    (uintmax_t)archive_entry_size(e),
-		    buf, archive_entry_pathname(e));
-	} else if (v_opt == 2) {
-		printf("%8ju  Stored  %7ju   0%%  %s  %08x  %s\n",
-		    (uintmax_t)archive_entry_size(e),
-		    (uintmax_t)archive_entry_size(e),
-		    buf,
-		    0U,
-		    archive_entry_pathname(e));
+	if (!zipinfo_mode) {
+		if (v_opt == 1) {
+			printf(" %8ju  %s   %s\n",
+			    (uintmax_t)archive_entry_size(e),
+			    buf, archive_entry_pathname(e));
+		} else if (v_opt == 2) {
+			printf("%8ju  Stored  %7ju   0%%  %s  %08x  %s\n",
+			    (uintmax_t)archive_entry_size(e),
+			    (uintmax_t)archive_entry_size(e),
+			    buf,
+			    0U,
+			    archive_entry_pathname(e));
+		}
+	} else {
+		if (Z1_opt)
+			printf("%s\n",archive_entry_pathname(e));
 	}
 	ac(archive_read_data_skip(a));
 }
@@ -870,14 +879,16 @@
 	ac(archive_read_support_format_zip(a));
 	ac(archive_read_open_fd(a, fd, 8192));
 
-	if (!p_opt && !q_opt)
-		printf("Archive:  %s\n", fn);
-	if (v_opt == 1) {
-		printf("  Length     Date   Time    Name\n");
-		printf(" --------    ----   ----    ----\n");
-	} else if (v_opt == 2) {
-		printf(" Length   Method    Size  Ratio   Date   Time   CRC-32    Name\n");
-		printf("--------  ------  ------- -----   ----   ----   ------    ----\n");
+	if (!zipinfo_mode) {
+		if (!p_opt && !q_opt)
+			printf("Archive:  %s\n", fn);
+		if (v_opt == 1) {
+			printf("  Length     Date   Time    Name\n");
+			printf(" --------    ----   ----    ----\n");
+		} else if (v_opt == 2) {
+			printf(" Length   Method    Size  Ratio   Date   Time   CRC-32    Name\n");
+			printf("--------  ------  ------- -----   ----   ----   ------    ----\n");
+		}
 	}
 
 	total_size = 0;
@@ -888,28 +899,35 @@
 		if (ret == ARCHIVE_EOF)
 			break;
 		ac(ret);
-		if (t_opt)
-			error_count += test(a, e);
-		else if (v_opt)
-			list(a, e);
-		else if (p_opt || c_opt)
-			extract_stdout(a, e);
-		else
-			extract(a, e);
+		if (!zipinfo_mode) {
+			if (t_opt)
+				error_count += test(a, e);
+			else if (v_opt)
+				list(a, e);
+			else if (p_opt || c_opt)
+				extract_stdout(a, e);
+			else
+				extract(a, e);
+		} else {
+			if (Z1_opt)
+				list(a, e);
+		}
 
 		total_size += archive_entry_size(e);
 		++file_count;
 	}
 
-	if (v_opt == 1) {
-		printf(" --------                   -------\n");
-		printf(" %8ju                   %ju file%s\n",
-		    total_size, file_count, file_count != 1 ? "s" : "");
-	} else if (v_opt == 2) {
-		printf("--------          -------  ---                            -------\n");
-		printf("%8ju          %7ju   0%%                            %ju file%s\n",
-		    total_size, total_size, file_count,
-		    file_count != 1 ? "s" : "");
+	if (zipinfo_mode) {
+		if (v_opt == 1) {
+			printf(" --------                   -------\n");
+			printf(" %8ju                   %ju file%s\n",
+			    total_size, file_count, file_count != 1 ? "s" : "");
+		} else if (v_opt == 2) {
+			printf("--------          -------  ---                            -------\n");
+			printf("%8ju          %7ju   0%%                            %ju file%s\n",
+			    total_size, total_size, file_count,
+			    file_count != 1 ? "s" : "");
+		}
 	}
 
 	ac(archive_read_close(a));
@@ -933,7 +951,7 @@
 usage(void)
 {
 
-	fprintf(stderr, "usage: unzip [-aCcfjLlnopqtuv] [-d dir] [-x pattern] zipfile\n");
+	fprintf(stderr, "usage: unzip [-aCcfjLlnopqtuvZ1] [-d dir] [-x pattern] zipfile\n");
 	exit(1);
 }
 
@@ -943,8 +961,11 @@
 	int opt;
 
 	optreset = optind = 1;
-	while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:")) != -1)
+	while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:Z1")) != -1)
 		switch (opt) {
+		case '1':
+			Z1_opt = 1;
+			break;
 		case 'a':
 			a_opt = 1;
 			break;
@@ -995,6 +1016,9 @@
 		case 'x':
 			add_pattern(&exclude, optarg);
 			break;
+		case 'Z':
+			zipinfo_mode = 1;
+			break;
 		default:
 			usage();
 		}
@@ -1024,6 +1048,15 @@
 	 */
 	nopts = getopts(argc, argv);
 
+	/* 
+	 * When more of the zipinfo mode options are implemented, this
+	 * will need to change.
+	 */
+	if (zipinfo_mode && !Z1_opt) {
+		printf("Zipinfo mode needs additional options\n");
+		exit(1);
+	}
+
 	if (argc <= nopts)
 		usage();
 	zipfile = argv[nopts++];
>Release-Note:
>Audit-Trail:
>Unformatted:



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