Package: gzip
Version: 1.3.12-6
Followup-For: Bug #506798
The attached patch adds a -T,--timestamp option to override the original
timestamp. It uses as its argument the number of seconds from the epoch.
Examples:
$ ./gzip -c zcat.1 | file -
/dev/stdin: gzip compressed data, was "zcat.1", from Unix, last modified: Thu
Oct 7 23:46:28 1999, max compression
$ ./gzip -c -T 1234567890 zcat.1 | file -
/dev/stdin: gzip compressed data, was "zcat.1", from Unix, last modified: Fri
Feb 13 15:31:30 2009, max compression
$ ./gzip -c < zcat.1 | file -
/dev/stdin: gzip compressed data, from Unix, last modified: Thu Oct 7 23:46:28
1999, max compression
$ ./gzip -c -T 1234567890 < zcat.1 | file -
/dev/stdin: gzip compressed data, from Unix, last modified: Fri Feb 13 15:31:30
2009, max compression
$ cat zcat.1 | ./gzip -c | file -
/dev/stdin: gzip compressed data, from Unix, last modified: Tue Nov 25 01:18:15
2008, max compression
$ cat zcat.1 | ./gzip -c -T 1234567890 | file -
/dev/stdin: gzip compressed data, from Unix, last modified: Fri Feb 13 15:31:30
2009, max compression
In creating this patch, I noticed that the long options structure
contains an entry mapping --no-time to -T, while the rest of gzip
suggests that --no-time (when compiled in) should map to -m. I fixed
this entry in the long options structure, and added the corresponding
entry for --time.
- Josh Triplett
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.27-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages gzip depends on:
ii debianutils 2.30 Miscellaneous utilities specific t
ii libc6 2.7-16 GNU C Library: Shared libraries
gzip recommends no packages.
Versions of packages gzip suggests:
ii less 418-1 Pager program similar to more
-- no debconf information
diff -Nurp gzip-1.3.12.override-original-filename/gzip.1 gzip-1.3.12/gzip.1
--- gzip-1.3.12.override-original-filename/gzip.1 2008-11-24 23:49:34.000000000 -0800
+++ gzip-1.3.12/gzip.1 2008-11-25 00:55:14.000000000 -0800
@@ -7,6 +7,7 @@ gzip, gunzip, zcat \- compress or expand
.RB [ " \-acdfhlLnNrtvV19 " ]
.RB [ \-F\ original_filename ]
.RB [ \-S\ suffix ]
+.RB [ \-T\ original_timestamp ]
[
.I "name \&..."
]
@@ -319,6 +320,11 @@ the .z suffix. This was changed to avoid
.B \-t --test
Test. Check the compressed file integrity.
.TP
+.B \-T original_timestamp --timestamp original_timestamp
+When compressing, store the specified original_timestamp (specified in seconds
+since the epoch of 1970-01-01 00:00:00 UTC) as the original time stamp in the
+gzip file, overriding the time stamp of the input file if any.
+.TP
.B \-v --verbose
Verbose. Display the name and percentage reduction for each file compressed
or decompressed.
diff -Nurp gzip-1.3.12.override-original-filename/gzip.c gzip-1.3.12/gzip.c
--- gzip-1.3.12.override-original-filename/gzip.c 2008-11-25 00:31:07.000000000 -0800
+++ gzip-1.3.12/gzip.c 2008-11-25 01:13:42.000000000 -0800
@@ -203,6 +203,7 @@ char *orig_name = NULL; /* overriding va
int last_member; /* set for .zip and .Z files */
int part_nb; /* number of parts in .gz file */
struct timespec time_stamp; /* original time stamp (modification time) */
+static int override_time = 0; /* override original timestamp */
off_t ifile_size; /* input file size, -1 for devices (debug only) */
char *env; /* contents of GZIP env variable */
char **args = NULL; /* argv pointer if GZIP env variable defined */
@@ -273,6 +274,8 @@ struct option longopts[] =
/* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
{"list", 0, 0, 'l'}, /* list .gz file contents */
{"license", 0, 0, 'L'}, /* display software license */
+ {"no-time", 0, 0, 'm'}, /* don't save or restore the time stamp */
+ {"time", 0, 0, 'M'}, /* save or restore the time stamp */
{"no-name", 0, 0, 'n'}, /* don't save or restore original name & time */
{"name", 0, 0, 'N'}, /* save or restore original name & time */
{"quiet", 0, 0, 'q'}, /* quiet mode */
@@ -280,7 +283,7 @@ struct option longopts[] =
{"recursive", 0, 0, 'r'}, /* recurse through directories */
{"suffix", 1, 0, 'S'}, /* use given suffix instead of .gz */
{"test", 0, 0, 't'}, /* test compressed file integrity */
- {"no-time", 0, 0, 'T'}, /* don't save or restore the time stamp */
+ {"timestamp", 1, 0, 'T'}, /* override original time stamp */
{"verbose", 0, 0, 'v'}, /* verbose mode */
{"version", 0, 0, 'V'}, /* display version number */
{"fast", 0, 0, '1'}, /* compress faster */
@@ -362,6 +365,7 @@ local void help()
#endif
" -S, --suffix=SUF use suffix SUF on compressed files",
" -t, --test test compressed file integrity",
+ " -T, --timestamp=T store T (seconds from the epoch) as original timestamp",
" -v, --verbose verbose mode",
" -V, --version display version number",
" -1, --fast compress faster",
@@ -453,7 +457,7 @@ int main (argc, argv)
z_suffix = Z_SUFFIX;
z_len = strlen(z_suffix);
- while ((optc = getopt_long (argc, argv, "ab:cdfF:hH?lLmMnNqrS:tvVZ123456789",
+ while ((optc = getopt_long (argc, argv, "ab:cdfF:hH?lLmMnNqrS:tT:vVZ123456789",
longopts, (int *)0)) != -1) {
switch (optc) {
case 'a':
@@ -513,6 +517,17 @@ int main (argc, argv)
case 't':
test = decompress = to_stdout = 1;
break;
+ case 'T':
+ override_time = 1;
+ time_stamp.tv_sec = atoi(optarg);
+ for (; *optarg; optarg++)
+ if (! ('0' <= *optarg && *optarg <= '9'))
+ {
+ fprintf (stderr, "%s: -T operand is not an integer\n",
+ program_name);
+ try_help ();
+ }
+ break;
case 'v':
verbose++; quiet = 0; break;
case 'V':
@@ -656,7 +671,7 @@ local void treat_stdin()
}
ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
time_stamp.tv_nsec = -1;
- if (!no_time || list)
+ if (!override_time && (!no_time || list))
time_stamp = get_stat_mtime (&istat);
clear_bufs(); /* clear input and output buffers */
@@ -786,7 +801,7 @@ local void treat_file(iname)
ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
time_stamp.tv_nsec = -1;
- if (!no_time || list)
+ if (!override_time && (!no_time || list))
time_stamp = get_stat_mtime (&istat);
/* Generate output file name. For -r and (-t or -l), skip files