bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: supporting -k/--keep?


From: Mike Frysinger
Subject: Re: supporting -k/--keep?
Date: Mon, 18 Jun 2012 01:22:51 -0400
User-agent: KMail/1.13.7 (Linux/3.4.0; KDE/4.6.5; x86_64; ; )

On Wednesday 15 February 2012 07:38:25 address@hidden wrote:
> this is about supporting -k/--keep, like bzip2 and xz do. (Strictly, not a
> bug, just a missing feature.)
> 
> I know this was suggested several years ago by at least a few people and I
> vaguely remember having seen that someone other than me provided a patch
> for it. But gzip still does not support the -k option. So, is there a
> reason for that?
> 
> In case there's not: Looking into the sources of version 1.4, a patch was
> quickly done - attached here. It's a very simple thing and shouldn't be
> able to break anything, except that I found a commented out option
> -k/--pkzip which I left commented out but changed to -p/--pkzip since -p
> was not used otherwise.
> 
> Why it's (still) wanted: Once in a while I "test" some compressors for
> speed and compression ratio: 7z, bzip2, xz, gzip. I'd like to try gzip
> first because it's likely to be the fastest and would give me an overview
> about what I can expect, but since it does not support -k and I obviously
> need the input file in it's original state, gzip always gets the last
> place in the line. I guess I'm not alone with this.

yes, it seems weird that this has been requested many times over the years,
but no one has really responded with a "yes" or "no" to the idea.

i've redone the patch against latest git as it doesn't apply and had style
issues.  i've also left the pkzip option alone for when someone cares to
actually do something with it.
-mike

From c4e569a4a6e73701512b8e07e0e6e6d500d7586d Mon Sep 17 00:00:00 2001
From: Mike Frysinger <address@hidden>
Date: Mon, 18 Jun 2012 01:13:01 -0400
Subject: [PATCH] gzip: add --keep/-k support

Signed-off-by: Mike Frysinger <address@hidden>
---
 gunzip.in |    1 +
 gzip.c    |   12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gunzip.in b/gunzip.in
index 2668d80..657c72e 100644
--- a/gunzip.in
+++ b/gunzip.in
@@ -38,6 +38,7 @@ Mandatory arguments to long options are mandatory for short 
options too.
 
   -c, --stdout      write on standard output, keep original files unchanged
   -f, --force       force overwrite of output file and compress links
+  -k, --keep        keep (don't delete) input files
   -l, --list        list compressed file contents
   -n, --no-name     do not save or restore the original name and time stamp
   -N, --name        save or restore the original name and time stamp
diff --git a/gzip.c b/gzip.c
index 35b3603..975bea1 100644
--- a/gzip.c
+++ b/gzip.c
@@ -169,6 +169,7 @@ static int force = 0;        /* don't ask questions, 
compress links (-f) */
 static int no_name = -1;     /* don't save or restore the original file name */
 static int no_time = -1;     /* don't save or restore the original file time */
 static int recursive = 0;    /* recurse through directories (-r) */
+static int keep = 0;         /* keep (don't delete) input files */
 static int list = 0;         /* list the file contents (-l) */
        int verbose = 0;      /* be verbose (-v) */
        int quiet = 0;        /* be very quiet (-q) */
@@ -253,6 +254,7 @@ static const struct option longopts[] =
     {"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'}, /* keep (don't delete) input files */
     {"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 */
@@ -331,6 +333,7 @@ local void help()
  "  -f, --force       force overwrite of output file and compress links",
  "  -h, --help        give this help",
 /*  -k, --pkzip       force output in pkzip format */
+ "  -k, --keep        keep (don't delete) input files",
  "  -l, --list        list compressed file contents",
  "  -L, --license     display software license",
 #ifdef UNDOCUMENTED
@@ -434,7 +437,7 @@ int main (int argc, char **argv)
     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':
@@ -457,6 +460,8 @@ int main (int argc, char **argv)
             force++; break;
         case 'h': case 'H':
             help(); do_exit(OK); break;
+        case 'k':
+            keep = 1; break;
         case 'l':
             list = decompress = to_stdout = 1; break;
         case 'L':
@@ -857,7 +862,10 @@ local void treat_file(iname)
 
         sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
         remove_ofname_fd = -1;
-        unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+        if (keep)
+          unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+        else
+          unlink_errno = 0;
         sigprocmask (SIG_SETMASK, &oldset, NULL);
 
         if (unlink_errno)
-- 
1.7.9.7



reply via email to

[Prev in Thread] Current Thread [Next in Thread]