Split comparing more fields and consistency checks. Consistency checks are very strict and it makes sense to check for more fields without it.
diff --git a/man/zipcmp.mdoc b/man/zipcmp.mdoc index 84866de..c29ee69 100644 --- a/man/zipcmp.mdoc +++ b/man/zipcmp.mdoc
@@ -29,7 +29,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 18, 2017 +.Dd March 4, 2021 .Dt ZIPCMP 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd compare contents of zip archives .Sh SYNOPSIS .Nm -.Op Fl hipqtVv +.Op Fl ChipqtVv .Ar archive1 archive2 .Sh DESCRIPTION .Nm @@ -51,6 +51,10 @@ .Pp Supported options: .Bl -tag -width MMM +.It Fl C +Check consistency of archives. +Results in an error if archive is inconsistent or not valid +according to the zip specification. .It Fl h Display a short help message and exit. .It Fl i
diff --git a/src/zipcmp.c b/src/zipcmp.c index ecfe24d..2edfc83 100644 --- a/src/zipcmp.c +++ b/src/zipcmp.c
@@ -94,6 +94,7 @@ char help[] = "\n\ -h display this help message\n\ + -C check archive consistencies\n\ -i compare names ignoring case distinctions\n\ -p compare as many details as possible\n\ -q be quiet\n\ @@ -107,7 +108,7 @@ Copyright (C) 2003-2020 Dieter Baron and Thomas Klausner\n\ " PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n"; -#define OPTIONS "hVipqtv" +#define OPTIONS "hVCipqtv" #define BOTH_ARE_ZIPS(a) (a[0].za && a[1].za) @@ -130,7 +131,7 @@ static int list_zip(const char *name, struct archive *a); static int test_file(zip_t *za, zip_uint64_t idx, const char *zipname, const char *filename, zip_uint64_t size, zip_uint32_t crc); -int ignore_case, test_files, paranoid, verbose, have_directory; +int ignore_case, test_files, paranoid, verbose, have_directory, check_consistency; int header_done; @@ -142,40 +143,43 @@ ignore_case = 0; test_files = 0; + check_consistency = 0; paranoid = 0; have_directory = 0; verbose = 1; while ((c = getopt(argc, argv, OPTIONS)) != -1) { switch (c) { - case 'i': - ignore_case = 1; - break; - case 'p': - paranoid = 1; - break; - case 'q': - verbose = 0; - break; - case 't': - test_files = 1; - break; - case 'v': - verbose = 1; - break; - - case 'h': - fputs(help_head, stdout); - printf(USAGE, progname); - fputs(help, stdout); - exit(0); - case 'V': - fputs(version_string, stdout); - exit(0); - - default: - fprintf(stderr, USAGE, progname); - exit(2); + case 'C': + check_consistency = 1; + case 'i': + ignore_case = 1; + break; + case 'p': + paranoid = 1; + break; + case 'q': + verbose = 0; + break; + case 't': + test_files = 1; + break; + case 'v': + verbose = 1; + break; + + case 'h': + fputs(help_head, stdout); + printf(USAGE, progname); + fputs(help, stdout); + exit(0); + case 'V': + fputs(version_string, stdout); + exit(0); + + default: + fprintf(stderr, USAGE, progname); + exit(2); } } @@ -410,7 +414,7 @@ struct zip_stat st; unsigned int i; - if ((za = zip_open(name, paranoid ? ZIP_CHECKCONS : 0, &err)) == NULL) { + if ((za = zip_open(name, check_consistency ? ZIP_CHECKCONS : 0, &err)) == NULL) { zip_error_t error; zip_error_init_with_code(&error, err); fprintf(stderr, "%s: cannot open zip archive '%s': %s\n", progname, name, zip_error_strerror(&error));