Partially implement zipinfo (-Z) support.

This fixes some test failures seen with perl 5.12 and 5.14.

PR:	bin/166895
Submitted by:	swills
MFC after:	3 days
This commit is contained in:
Kevin Lo 2012-04-13 06:15:51 +00:00
parent 8a138d80d0
commit 308633f39e

View File

@ -65,6 +65,7 @@ static int q_opt; /* quiet */
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 @@ static time_t now;
/* debug flag */
static int unzip_debug;
/* zipinfo mode */
static int zipinfo_mode;
/* running on tty? */
static int tty;
@ -802,6 +806,7 @@ list(struct archive *a, struct archive_entry *e)
mtime = archive_entry_mtime(e);
strftime(buf, sizeof(buf), "%m-%d-%g %R", localtime(&mtime));
if (!zipinfo_mode) {
if (v_opt == 1) {
printf(" %8ju %s %s\n",
(uintmax_t)archive_entry_size(e),
@ -814,6 +819,10 @@ list(struct archive *a, struct archive_entry *e)
0U,
archive_entry_pathname(e));
}
} else {
if (Z1_opt)
printf("%s\n",archive_entry_pathname(e));
}
ac(archive_read_data_skip(a));
}
@ -870,6 +879,7 @@ unzip(const char *fn)
ac(archive_read_support_format_zip(a));
ac(archive_read_open_fd(a, fd, 8192));
if (!zipinfo_mode) {
if (!p_opt && !q_opt)
printf("Archive: %s\n", fn);
if (v_opt == 1) {
@ -879,6 +889,7 @@ unzip(const char *fn)
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
printf("-------- ------ ------- ----- ---- ---- ------ ----\n");
}
}
total_size = 0;
file_count = 0;
@ -888,6 +899,7 @@ unzip(const char *fn)
if (ret == ARCHIVE_EOF)
break;
ac(ret);
if (!zipinfo_mode) {
if (t_opt)
error_count += test(a, e);
else if (v_opt)
@ -896,11 +908,16 @@ unzip(const char *fn)
extract_stdout(a, e);
else
extract(a, e);
} else {
if (Z1_opt)
list(a, e);
}
total_size += archive_entry_size(e);
++file_count;
}
if (zipinfo_mode) {
if (v_opt == 1) {
printf(" -------- -------\n");
printf(" %8ju %ju file%s\n",
@ -911,6 +928,7 @@ unzip(const char *fn)
total_size, total_size, file_count,
file_count != 1 ? "s" : "");
}
}
ac(archive_read_close(a));
(void)archive_read_finish(a);
@ -933,7 +951,7 @@ static void
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 @@ getopts(int argc, char *argv[])
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 @@ getopts(int argc, char *argv[])
case 'x':
add_pattern(&exclude, optarg);
break;
case 'Z':
zipinfo_mode = 1;
break;
default:
usage();
}
@ -1024,6 +1048,15 @@ main(int argc, char *argv[])
*/
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++];