bug-gzip
[Top][All Lists]
Advanced

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

Re: [PATCH v6] gzip: add "--keep" option to keep (don't delete) input fi


From: Jim Meyering
Subject: Re: [PATCH v6] gzip: add "--keep" option to keep (don't delete) input files
Date: Mon, 27 May 2013 03:36:03 +0200

Rodrigo Campos wrote:

> On Wed, Apr 17, 2013 at 11:01:51PM +0200, Jim Meyering wrote:
>> Rodrigo Campos wrote:
>>
>> > On Wed, Apr 17, 2013 at 12:28:08AM -0300, Rodrigo Campos wrote:
>> >> On Wed, Apr 17, 2013 at 05:21:59AM +0200, Jim Meyering wrote:
>> >> > Rodrigo Campos wrote:
>> >> > > On Sun, Apr 14, 2013 at 04:36:38PM +0200, Jim Meyering wrote:
>> >> > >> Rodrigo Campos wrote:
>> >> > >> > On Sun, Apr 14, 2013 at 07:26:35AM +0200, Jim Meyering wrote:
>> >> > >> >> Rodrigo Campos wrote:
>> >> > >> >>
>> >> > >> Please tell me when you've posted the piece of paper to the FSF.
>> >> > >
>> >> > > I've sent the email to address@hidden on Sunday and they have
>> >> > > never replied me
>> >> > > yet. Do you know if this delay is normal ? Is it some automatic reply 
>> >> > > ?
>> >> >
>> >> > It's not surprising.
>> >> > There's only one person working part time to deal with all such
>> >> > submissions, and sometimes he's away.
>> >>
>> >> Ohh, good to know this is normal :-)
>> >
>> > Hey, they sent me the form today and I've just sent it! :-)
>> >
>> > It may take up to two weeks to get there
>>
>> Good.
>> Thanks for the info.
>
> Btw, I have already received the confirmation that everything is okay. So feel
> free to commit my last patch sent to the list (with a test case and all that
> stuff).

Thanks again.
I've adjusted NEWS and the commit log and added test cases.
I expect to push this tomorrow and to make a release in the
next week or so.

>From a6aa42c56789f8531352a795fff2dee598865064 Mon Sep 17 00:00:00 2001
From: Rodrigo Campos <address@hidden>
Date: Sun, 31 Mar 2013 22:53:31 -0300
Subject: [PATCH 1/2] gzip: add "--keep" option to retain (don't delete) input
 files

gzip now accepts the --keep (-k) option, for consistency with tools
like xz, lzip and bzip2.  With this option, gzip no longer removes
named input files when compressing and decompressing.
* doc/gzip.texi: Document it.
* gzip.1: Likewise.
* gunzip.in: Likewise.
* NEWS: Likewise.
* gzip.c: Add support for "--keep".
---
 NEWS          |  6 ++++++
 doc/gzip.texi |  5 +++++
 gunzip.in     |  1 +
 gzip.1        |  9 ++++++---
 gzip.c        | 35 ++++++++++++++++++++++-------------
 5 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/NEWS b/NEWS
index c8ae541..3dfffe2 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU gzip NEWS                                    -*- outline 
-*-

 * Noteworthy changes in release ?.? (????-??-??) [?]

+** New features
+
+  gzip now accepts the --keep (-k) option, for consistency with tools
+  like xz, lzip and bzip2.  With this option, gzip no longer removes
+  named input files when compressing and decompressing.
+
 ** Bug fixes

   gzip -d no longer malfunctions with certain invalid data in 'pack' format.
diff --git a/doc/gzip.texi b/doc/gzip.texi
index f7e45e1..3de3063 100644
--- a/doc/gzip.texi
+++ b/doc/gzip.texi
@@ -195,6 +195,7 @@ Mandatory arguments to long options are mandatory for short 
options too.
   -d, --decompress  decompress
   -f, --force       force overwrite of output file and compress links
   -h, --help        give this help
+  -k, --keep        keep (don't 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
@@ -276,6 +277,10 @@ whether an existing file should be overwritten.
 @itemx -h
 Print an informative help message describing the options then quit.

address@hidden --keep
address@hidden -k
+Keep (don't delete) input files during compression or decompression.
+
 @item --list
 @itemx -l
 For each compressed file, list the following fields:
diff --git a/gunzip.in b/gunzip.in
index b95e973..dbfd04b 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.1 b/gzip.1
index c97aeb1..71e097c 100644
--- a/gzip.1
+++ b/gzip.1
@@ -4,7 +4,7 @@ gzip, gunzip, zcat \- compress or expand files
 .SH SYNOPSIS
 .ll +8
 .B gzip
-.RB [ " \-acdfhlLnNrtvV19 " ]
+.RB [ " \-acdfhklLnNrtvV19 " ]
 .RB [ \-S\ suffix ]
 [
 .I "name \&..."
@@ -12,7 +12,7 @@ gzip, gunzip, zcat \- compress or expand files
 .ll -8
 .br
 .B gunzip
-.RB [ " \-acfhlLnNrtvV " ]
+.RB [ " \-acfhklLnNrtvV " ]
 .RB [ \-S\ suffix ]
 [
 .I "name \&..."
@@ -218,6 +218,9 @@ prompts to verify whether an existing file should be 
overwritten.
 .B \-h --help
 Display a help screen and quit.
 .TP
+.B \-k --keep
+Keep (don't delete) input files during compression or decompression.
+.TP
 .B \-l --list
 For each compressed file, list the following fields:

@@ -392,7 +395,7 @@ Internet RFC 1951 (May 1996).
 Exit status is normally 0;
 if an error occurs, exit status is 1. If a warning occurs, exit status is 2.
 .TP
-Usage: gzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
+Usage: gzip [-cdfhklLnNrtvV19] [-S suffix] [file ...]
 Invalid options were specified on the command line.
 .TP
 \fIfile\fP\^: not in gzip format
diff --git a/gzip.c b/gzip.c
index 66529e0..93cc738 100644
--- a/gzip.c
+++ b/gzip.c
@@ -167,6 +167,7 @@ static int ascii = 0;        /* convert end-of-lines to 
local OS conventions */
        int to_stdout = 0;    /* output to stdout (-c) */
 static int decompress = 0;   /* decompress (-d) */
 static int force = 0;        /* don't ask questions, compress links (-f) */
+static int keep = 0;         /* keep (don't delete) input files */
 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) */
@@ -256,6 +257,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 */
@@ -334,6 +336,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
@@ -437,7 +440,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':
@@ -460,6 +463,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':
@@ -851,25 +856,29 @@ local void treat_file(iname)

     if (!to_stdout)
       {
-        sigset_t oldset;
-        int unlink_errno;

         copy_stat (&istat);
         if (close (ofd) != 0)
           write_error ();

-        sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
-        remove_ofname_fd = -1;
-        unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
-        sigprocmask (SIG_SETMASK, &oldset, NULL);
-
-        if (unlink_errno)
+        if (!keep)
           {
-            WARN ((stderr, "%s: ", program_name));
-            if (!quiet)
+            sigset_t oldset;
+            int unlink_errno;
+
+            sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+            remove_ofname_fd = -1;
+            unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+            sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+            if (unlink_errno)
               {
-                errno = unlink_errno;
-                perror (ifname);
+                WARN ((stderr, "%s: ", program_name));
+                if (!quiet)
+                  {
+                    errno = unlink_errno;
+                    perror (ifname);
+                  }
               }
           }
       }
--
1.8.3


>From c4eb3bc76fca17999d2b8fd8d8199e424215d0d7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 26 May 2013 11:52:17 -0700
Subject: [PATCH 2/2] tests: exercise the new --keep option

* tests/keep: New file.
* tests/Makefile.am (TESTS): Add it.
---
 tests/Makefile.am |  1 +
 tests/keep        | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100755 tests/keep

diff --git a/tests/Makefile.am b/tests/Makefile.am
index ad08601..53bfffa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,7 @@ TESTS =                                       \
   helin-segv                           \
   help-version                         \
   hufts                                        \
+  keep                                 \
   memcpy-abuse                         \
   mixed                                        \
   null-suffix-clobber                  \
diff --git a/tests/keep b/tests/keep
new file mode 100755
index 0000000..b2bbcd3
--- /dev/null
+++ b/tests/keep
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Exercise the --keep option.
+
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# limit so don't run it by default.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ..
+
+echo fooooooooo > in || framework_failure_
+cp in orig || framework_failure_
+
+fail=0
+
+# Compress and decompress both with and without --keep.
+for k in --keep ''; do
+  # With --keep, the source must be retained, otherwise, it must be removed.
+  case $k in --keep) op='||' ;; *) op='&&' ;; esac
+
+  gzip $k in || fail=1
+  eval "test -f in $op fail=1"
+  test -f in.gz || fail=1
+  rm -f in || fail=1
+
+  gzip -d $k in.gz || fail=1
+  eval "test -f in.gz $op fail=1"
+  test -f in || fail=1
+  compare in orig || fail=1
+  rm -f in.gz || fail=1
+done
+
+Exit $fail
--
1.8.3



reply via email to

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