Skip to content

Commit 1400a74

Browse files
committed
zipcmp: add -T for comparing time stamps
1 parent 5ef08f2 commit 1400a74

File tree

7 files changed

+244
-235
lines changed

7 files changed

+244
-235
lines changed

man/zipcmp.html

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/zipcmp.man

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated from an mdoc input file. Do not edit.
22
.\" zipcmp.mdoc -- compare zip archives
3-
.\" Copyright (C) 2003-2022 Dieter Baron and Thomas Klausner
3+
.\" Copyright (C) 2003-2024 Dieter Baron and Thomas Klausner
44
.\"
55
.\" This file is part of libzip, a library to manipulate ZIP archives.
66
.\" The authors can be contacted at <[email protected]>
@@ -30,7 +30,7 @@
3030
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
3131
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
.\"
33-
.TH "ZIPCMP" "1" "March 19, 2022" "NiH" "General Commands Manual"
33+
.TH "ZIPCMP" "1" "March 15, 2024" "NiH" "General Commands Manual"
3434
.nh
3535
.if n .ad l
3636
.SH "NAME"
@@ -39,7 +39,7 @@
3939
.SH "SYNOPSIS"
4040
.HP 7n
4141
\fBzipcmp\fR
42-
[\fB\-ChipqstVv\fR]
42+
[\fB\-ChipqsTtVv\fR]
4343
\fIarchive1\ archive2\fR
4444
.SH "DESCRIPTION"
4545
\fBzipcmp\fR
@@ -78,6 +78,9 @@ Compare
7878
\fB\-s\fR
7979
Print a summary of how many files where added and removed.
8080
.TP 5n
81+
\fB\-T\fR
82+
Additionally compare the time stamps of the entries.
83+
.TP 5n
8184
\fB\-t\fR
8285
Test zip files by comparing the contents to their checksums.
8386
.TP 5n

man/zipcmp.mdoc

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" zipcmp.mdoc -- compare zip archives
2-
.\" Copyright (C) 2003-2022 Dieter Baron and Thomas Klausner
2+
.\" Copyright (C) 2003-2024 Dieter Baron and Thomas Klausner
33
.\"
44
.\" This file is part of libzip, a library to manipulate ZIP archives.
55
.\" The authors can be contacted at <[email protected]>
@@ -29,15 +29,15 @@
2929
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
3030
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
.\"
32-
.Dd March 19, 2022
32+
.Dd March 15, 2024
3333
.Dt ZIPCMP 1
3434
.Os
3535
.Sh NAME
3636
.Nm zipcmp
3737
.Nd compare contents of zip archives
3838
.Sh SYNOPSIS
3939
.Nm
40-
.Op Fl ChipqstVv
40+
.Op Fl ChipqsTtVv
4141
.Ar archive1 archive2
4242
.Sh DESCRIPTION
4343
.Nm
@@ -70,6 +70,8 @@ Compare
7070
.Fl v .
7171
.It Fl s
7272
Print a summary of how many files where added and removed.
73+
.It Fl T
74+
Additionally compare the time stamps of the entries.
7375
.It Fl t
7476
Test zip files by comparing the contents to their checksums.
7577
.It Fl V

regress/zipcmp_zip_dir.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ stdout
1111
--- zipcmp_zip_dir.zip
1212
+++ a
1313
- directory '00-empty-dir/'
14-
- file 'dir-with-file/a', size 1, crc e8b7be43
14+
- file 'dir-with-file/a', size 1, crc e8b7be43, mtime 0
1515
+ directory 'empty-dir-in-dir/'
1616
- directory 'empty-dir/'
1717
end-of-inline-data

src/diff_output.c

+25-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
#include "compat.h"
99

10-
static void ensure_header(diff_output_t *output) {
10+
static void
11+
ensure_header(diff_output_t *output) {
1112
if (output->archive_names[0] != NULL) {
1213
printf("--- %s\n", output->archive_names[0]);
1314
printf("+++ %s\n", output->archive_names[1]);
@@ -16,63 +17,71 @@ static void ensure_header(diff_output_t *output) {
1617
}
1718
}
1819

19-
void diff_output_init(diff_output_t *output, int verbose, char *const archive_names[]) {
20+
void
21+
diff_output_init(diff_output_t *output, int verbose, char *const archive_names[]) {
2022
output->archive_names[0] = archive_names[0];
2123
output->archive_names[1] = archive_names[1];
2224
output->verbose = verbose;
2325
output->file_name = NULL;
2426
output->file_size = 0;
2527
output->file_crc = 0;
28+
output->file_mtime = 0;
2629
}
2730

28-
void diff_output_start_file(diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc) {
31+
void
32+
diff_output_start_file(diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc, zip_uint64_t mtime) {
2933
output->file_name = name;
3034
output->file_size = size;
3135
output->file_crc = crc;
36+
output->file_mtime = mtime;
3237
}
3338

34-
void diff_output_end_file(diff_output_t *output) {
39+
void
40+
diff_output_end_file(diff_output_t *output) {
3541
output->file_name = NULL;
3642
}
3743

38-
void diff_output(diff_output_t *output, int side, const char *fmt, ...) {
44+
void
45+
diff_output(diff_output_t *output, int side, const char *fmt, ...) {
3946
va_list ap;
4047

4148
if (!output->verbose) {
4249
return;
4350
}
4451

4552
ensure_header(output);
46-
53+
4754
if (output->file_name != NULL) {
48-
diff_output_file(output, ' ', output->file_name, output->file_size, output->file_crc);
55+
diff_output_file(output, ' ', output->file_name, output->file_size, output->file_crc, output->file_mtime);
4956
output->file_name = NULL;
5057
}
51-
58+
5259
printf("%c ", side);
5360
va_start(ap, fmt);
5461
vprintf(fmt, ap);
5562
va_end(ap);
5663
printf("\n");
5764
}
5865

59-
void diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc) {
66+
void
67+
diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc, zip_uint64_t mtime) {
6068
if (!output->verbose) {
6169
return;
6270
}
63-
71+
6472
ensure_header(output);
65-
73+
6674
if (size == 0 && crc == 0 && name[0] != '\0' && name[strlen(name) - 1] == '/') {
6775
printf("%c directory '%s'\n", side, name);
6876
}
6977
else {
70-
printf("%c file '%s', size %" PRIu64 ", crc %08x\n", side, name, size, crc);
78+
printf("%c file '%s', size %" PRIu64 ", crc %08x, mtime %" PRIu64 "\n", side, name, size, crc, mtime);
7179
}
7280
}
7381

7482
#define MAX_BYTES 64
75-
void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt, ...) {
83+
void
84+
diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt, ...) {
7685
char prefix[1024];
7786
char hexdata[MAX_BYTES * 3 + 6];
7887
size_t i, offset;
@@ -81,7 +90,7 @@ void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data,
8190
if (!output->verbose) {
8291
return;
8392
}
84-
93+
8594
offset = 0;
8695
for (i = 0; i < data_length; i++) {
8796
hexdata[offset++] = (i == 0 ? '<' : ' ');
@@ -96,11 +105,11 @@ void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data,
96105

97106
hexdata[offset++] = '>';
98107
hexdata[offset] = '\0';
99-
108+
100109
va_start(ap, fmt);
101110
vsnprintf(prefix, sizeof(prefix), fmt, ap);
102111
va_end(ap);
103112
prefix[sizeof(prefix) - 1] = '\0';
104-
113+
105114
diff_output(output, side, "%s, length %" PRIu64 ", data %s", prefix, data_length, hexdata);
106115
}

src/diff_output.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ typedef struct {
88
const char *file_name;
99
zip_uint64_t file_size;
1010
zip_uint32_t file_crc;
11+
zip_uint64_t file_mtime;
1112
int verbose;
1213
} diff_output_t;
1314

@@ -18,11 +19,11 @@ typedef struct {
1819
#endif
1920

2021
void diff_output_init(diff_output_t *output, int verbose, char *const archive_names[]);
21-
void diff_output_start_file(diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc);
22+
void diff_output_start_file(diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc, zip_uint64_t mtime);
2223
void diff_output_end_file(diff_output_t *output);
2324

2425
void diff_output(diff_output_t *output, int side, const char *fmt, ...) PRINTF_LIKE(3, 4);
2526
void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt, ...) PRINTF_LIKE(5, 6);
26-
void diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc);
27+
void diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc, zip_uint64_t mtime);
2728

2829
#endif /* HAD_DIFF_OUTPUT_H */

0 commit comments

Comments
 (0)