Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#240539: gzip: "keep input files" option

1 view
Skip to first unread message

Peter Samuelson

unread,
Mar 27, 2004, 7:20:13 PM3/27/04
to

Package: gzip
Version: 1.3.5-7
Severity: wishlist
Tags: patch

Quite frequently I want to compress or uncompress a file, but also keep
the original file. The usual way is "gzip < file > file.gz" or the
converse, "zcat file.gz > file", but it would be more convenient to say
"gzip -k file" or "gunzip -k file.gz". (This is particularly true for
long pathnames.) The patch is trivial.

Peter

diff -u gzip-1.3.5/gzip.c gzip-1.3.5/gzip.c
--- gzip-1.3.5/gzip.c
+++ gzip-1.3.5/gzip.c
@@ -223,6 +223,7 @@
int no_time = -1; /* don't save or restore the original file time */
int recursive = 0; /* recurse through directories (-r) */
int list = 0; /* list the file contents (-l) */
+int keep_orig = 0; /* do not delete input file (-k) */
int verbose = 0; /* be verbose (-v) */
int quiet = 0; /* be very quiet (-q) */
int do_lzw = 0; /* generate output compatible with old compress (-Z) */
@@ -269,7 +270,7 @@
/* {"encrypt", 0, 0, 'e'}, encrypt */
{"force", 0, 0, 'f'}, /* force overwrite of output file */
{"help", 0, 0, 'h'}, /* give help */
- /* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
+ {"keep", 0, 0, 'k'}, /* don't delete original file */
{"list", 0, 0, 'l'}, /* list .gz file contents */
{"license", 0, 0, 'L'}, /* display software license */
{"no-name", 0, 0, 'n'}, /* don't save or restore original name & time */
@@ -344,7 +345,7 @@
/* -e --encrypt encrypt */
" -f --force force overwrite of output file and compress links",
" -h --help give this help",
-/* -k --pkzip force output in pkzip format */
+ " -k --keep do not delete input files after compressing/uncompressing",
" -l --list list compressed file contents",
" -L --license display software license",
#ifdef UNDOCUMENTED
@@ -500,7 +501,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:cdfhH?klLmMnNqrS:tvVZ123456789",
longopts, (int *)0)) != -1) {
switch (optc) {
case 'a':
@@ -524,6 +525,8 @@
force++; break;
case 'h': case 'H': case '?':
help(); do_exit(OK); break;
+ case 'k':
+ keep_orig = 1; break;
case 'l':
list = decompress = to_stdout = 1; break;
case 'L':
@@ -1744,7 +1747,7 @@
#endif
remove_ofname = 0;
/* It's now safe to remove the input file: */
- if (xunlink (ifname)) {
+ if (!keep_orig && xunlink (ifname)) {
int e = errno;
WARN((stderr, "%s: ", progname));
if (!quiet) {
diff -u gzip-1.3.5/gzip.texi gzip-1.3.5/gzip.texi
--- gzip-1.3.5/gzip.texi
+++ gzip-1.3.5/gzip.texi
@@ -82,7 +82,8 @@
@samp{z} for MSDOS, OS/2 FAT and Atari.) If no files are specified or
if a file name is "-", the standard input is compressed to the standard
output. @code{gzip} will only attempt to compress regular files. In
-particular, it will ignore symbolic links.
+particular, it will ignore symbolic links. The @code{-k} option
+suppresses deleting the input file after compressing it.

If the new file name is too long for its file system, @code{gzip}
truncates it. @code{gzip} attempts to truncate only the parts of the
@@ -111,7 +112,8 @@
@samp{.taz} as shorthands for @samp{.tar.gz} and @samp{.tar.Z}
respectively. When compressing, @code{gzip} uses the @samp{.tgz}
extension if necessary instead of truncating a file with a @samp{.tar}
-extension.
+extension. The @code{-k} option suppresses deleting the input file
+after uncompressing it.

@code{gunzip} can currently decompress files created by @code{gzip},
@code{zip}, @code{compress} or @code{pack}. The detection of the input
@@ -180,6 +182,7 @@
-d --decompress decompress
-f --force force overwrite of output file and compress links
-h --help give this help
+ -k --keep do not delete input files
-l --list list compressed file contents
-L --license display software license
-n --no-name do not save or restore the original name and time stamp
@@ -252,6 +255,13 @@
@itemx -h
Print an informative help message describing the options then quit.

+@item --keep
+@itemx -k
+Keep input files after compressing or decompressing them. By default,
+@code{gzip} deletes each input file after successfully writing and
+closing the corresponding output file. This option is meaningless with
+@samp{-c}, @samp{-l} or @samp{-t}.
+
@item --list
@itemx -l
For each compressed file, list the following fields:
diff -u gzip-1.3.5/gzip.1 gzip-1.3.5/gzip.1
--- gzip-1.3.5.orig/gzip.1
+++ gzip-1.3.5/gzip.1
@@ -4,7 +4,7 @@
.SH SYNOPSIS
.ll +8
.B gzip
-.RB [ " \-acdfhlLnNrtvV19 " ]
+.RB [ " \-acdfhklLnNrtvV19 " ]
.RB [ \-S\ suffix ]
[
.I "name \&..."
@@ -12,7 +12,7 @@
.ll -8
.br
.B gunzip
-.RB [ " \-acfhlLnNrtvV " ]
+.RB [ " \-acfhklLnNrtvV " ]
.RB [ \-S\ suffix ]
[
.I "name \&..."
@@ -224,6 +224,16 @@
.B \-h --help
Display a help screen and quit.
.TP
+.B \-k --keep
+Keep input files after compressing or decompressing them. By default,
+.I gzip
+deletes each input file after successfully writing and closing the
+corresponding output file. This option is meaningless with
+.B \-c,
+.B \-l
+or
+.B \-t.
+.TP
.B \-l --list
For each compressed file, list the following fields:

signature.asc

Drew Scott Daniels

unread,
Mar 29, 2004, 1:00:22 PM3/29/04
to
On Sat, 27 Mar 2004, Peter Samuelson wrote:

> Package: gzip
> Version: 1.3.5-7
> Severity: wishlist

[...]


> - /* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
> + {"keep", 0, 0, 'k'}, /* don't delete original file */

While it sounds like a nice idea to have a "keep input files" option, I
certainly wouldn't want to see a flag as this one change its meaning or
accidentally have two meanings. Why was this comment put in for the -k
flag? It would be nice to clear that up before using this flag.

I notice that bzip2 uses -k or --keep to "keep (don't delete) input
files". It thus may be convenient to use the same flag.

Right now the best way to keep the original file seems to be to use the -c
flag and then redirect standard output (stout). In the future I hope a
patch such as the one attached to this bug gets applied.

Drew Daniels


--
To UNSUBSCRIBE, email to debian-bugs-...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Peter Samuelson

unread,
Mar 29, 2004, 3:00:25 PM3/29/04
to

[Drew Scott Daniels]

> > - /* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
> > + {"keep", 0, 0, 'k'}, /* don't delete original file */

> While it sounds like a nice idea to have a "keep input files" option, I
> certainly wouldn't want to see a flag as this one change its meaning or
> accidentally have two meanings. Why was this comment put in for the -k
> flag? It would be nice to clear that up before using this flag.

Yeah, I have no idea. I suppose I should have checked with older
versions of gzip to find out whether this flag was ever functional, and
if so, when. I'll look into it.

> I notice that bzip2 uses -k or --keep to "keep (don't delete) input
> files". It thus may be convenient to use the same flag.

Actually that's a coincidence - somehow I managed to think of those
long *and* short option names without even noticing that bzip2 had
them already. That does lend some weight to the argument for using -k,
though.

Peter

signature.asc
0 new messages