Package: gzip
Version: 1.3.12-6
Followup-For: Bug #506798
The attached patch adds a -F,--filename option which overrides the
original filename. Examples:
$ ./gzip -c gzip | file -
/dev/stdin: gzip compressed data, was "gzip", from Unix, last modified: Tue Nov
25 00:41:19 2008, max compression
$ ./gzip -c -F foo gzip | file -
/dev/stdin: gzip compressed data, was "foo", from Unix, last modified: Tue Nov
25 00:41:19 2008, max compression
$ ./gzip -c < gzip | file -
/dev/stdin: gzip compressed data, from Unix, last modified: Tue Nov 25 00:41:19
2008, max compression
$ ./gzip -c -F foo < gzip | file -
/dev/stdin: gzip compressed data, was "foo", from Unix, last modified: Tue Nov
25 00:41:19 2008, max compression
- 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 -Nur gzip-1.3.12.orig/gzip.1 gzip-1.3.12/gzip.1
--- gzip-1.3.12.orig/gzip.1 2008-11-24 23:22:32.000000000 -0800
+++ gzip-1.3.12/gzip.1 2008-11-24 23:49:34.000000000 -0800
@@ -5,6 +5,7 @@
.ll +8
.B gzip
.RB [ " \-acdfhlLnNrtvV19 " ]
+.RB [ \-F\ original_filename ]
.RB [ \-S\ suffix ]
[
.I "name \&..."
@@ -221,6 +222,10 @@
.I gzip
prompts to verify whether an existing file should be overwritten.
.TP
+.B \-F original_filename --filename original_filename
+When compressing, store the specified original_filename as the original
+filename in the gzip file, overriding the name of the input file if any.
+.TP
.B \-h --help
Display a help screen and quit.
.TP
diff -Nur gzip-1.3.12.orig/gzip.c gzip-1.3.12/gzip.c
--- gzip-1.3.12.orig/gzip.c 2008-11-24 23:22:32.000000000 -0800
+++ gzip-1.3.12/gzip.c 2008-11-25 00:31:07.000000000 -0800
@@ -199,6 +199,7 @@
int level = 6; /* compression level */
int exit_code = OK; /* program exit code */
int save_orig_name; /* set if original name must be saved */
+char *orig_name = NULL; /* overriding value for original name */
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) */
@@ -267,6 +268,7 @@
{"uncompress", 0, 0, 'd'}, /* decompress */
/* {"encrypt", 0, 0, 'e'}, encrypt */
{"force", 0, 0, 'f'}, /* force overwrite of output file */
+ {"filename", 1, 0, 'F'}, /* override original filename */
{"help", 0, 0, 'h'}, /* give help */
/* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
{"list", 0, 0, 'l'}, /* list .gz file contents */
@@ -343,6 +345,7 @@
" -d, --decompress decompress",
/* -e, --encrypt encrypt */
" -f, --force force overwrite of output file and compress links",
+ " -F, --filename=FN store FN as original filename, overriding input filename",
" -h, --help give this help",
/* -k, --pkzip force output in pkzip format */
" -l, --list list compressed file contents",
@@ -450,7 +453,7 @@
z_suffix = Z_SUFFIX;
z_len = strlen(z_suffix);
- while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
+ while ((optc = getopt_long (argc, argv, "ab:cdfF:hH?lLmMnNqrS:tvVZ123456789",
longopts, (int *)0)) != -1) {
switch (optc) {
case 'a':
@@ -471,6 +474,8 @@
decompress = 1; break;
case 'f':
force++; break;
+ case 'F':
+ orig_name = optarg; break;
case 'h': case 'H':
help(); do_exit(OK); break;
case 'l':
@@ -641,6 +646,8 @@
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
+ save_orig_name = orig_name ? 1 : 0;
+
/* Get the file's time stamp and size. */
if (fstat (fileno (stdin), &istat) != 0)
{
@@ -826,7 +833,7 @@
}
}
/* Keep the name even if not truncated except with --no-name: */
- if (!save_orig_name) save_orig_name = !no_name;
+ if (!save_orig_name) save_orig_name = orig_name || !no_name;
if (verbose) {
fprintf(stderr, "%s:\t", ifname);
diff -Nur gzip-1.3.12.orig/gzip.h gzip-1.3.12/gzip.h
--- gzip-1.3.12.orig/gzip.h 2008-11-24 23:22:32.000000000 -0800
+++ gzip-1.3.12/gzip.h 2008-11-25 00:06:44.000000000 -0800
@@ -223,6 +223,7 @@
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
+extern char *orig_name; /* overriding value for original name */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
#define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
diff -Nur gzip-1.3.12.orig/zip.c gzip-1.3.12/zip.c
--- gzip-1.3.12.orig/zip.c 2007-03-19 22:09:51.000000000 -0700
+++ gzip-1.3.12/zip.c 2008-11-25 00:03:22.000000000 -0800
@@ -82,7 +82,12 @@
put_byte(OS_CODE); /* OS identifier */
if (save_orig_name) {
- char *p = gzip_base_name (ifname); /* Don't save the directory part. */
+ char *p;
+ if (orig_name) {
+ p = orig_name;
+ } else {
+ p = gzip_base_name (ifname); /* Don't save the directory part. */
+ }
do {
put_char(*p);
} while (*p++);