From: Hasso Tepper Date: Thu, 6 Dec 2007 19:54:52 +0000 (+0000) Subject: - Add a '-k' option which does not remove input file, like bzip2(1) do. X-Git-Tag: v2.0.1~1648 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/b5fbfbf2d0503ca5eacf06dd55fe48944d83cb5c - Add a '-k' option which does not remove input file, like bzip2(1) do. - Use better representation of 'S:' by expanding ':' to '.suffix' - Simulate GNU gzip(1) behavior where full filename is being output in verbose mode when doing recursive[1]. Submitted-by: Xin LI Obtained-from: FreeBSD --- diff --git a/usr.bin/gzip/gzip.1 b/usr.bin/gzip/gzip.1 index bd9bdb7710..c17f76f7c0 100644 --- a/usr.bin/gzip/gzip.1 +++ b/usr.bin/gzip/gzip.1 @@ -1,5 +1,5 @@ .\" $NetBSD: gzip.1,v 1.16 2004/04/27 02:25:06 mrg Exp $ -.\" $DragonFly: src/usr.bin/gzip/gzip.1,v 1.1 2004/10/26 11:19:31 joerg Exp $ +.\" $DragonFly: src/usr.bin/gzip/gzip.1,v 1.2 2007/12/06 19:54:52 hasso Exp $ .\" .\" Copyright (c) 1997, 2003, 2004 Matthew R. Green .\" All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 27, 2004 +.Dd December 6, 2007 .Dt GZIP 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd compression/decompression tool using Lempel-Ziv coding (LZ77) .Sh SYNOPSIS .Nm -.Op Fl cdfhlNnqrtVv +.Op Fl cdfhklNnqrtVv .Op Fl S Ar suffix .Ar file .Oo @@ -43,7 +43,7 @@ .Oc .Oc .Nm gunzip -.Op Fl cfhNqrtVv +.Op Fl cfhkNqrtVv .Op Fl S Ar suffix .Ar file .Oo @@ -130,6 +130,9 @@ with the option, allowing non-compressed data to pass through unchanged. .It Fl h , -help This option prints a usage summary and exits. +.It Fl k , -keep +Keep (don't delete) input files during compression +or decompression. .It Fl l , -list This option displays information about the file's compressed and uncompressed size, ratio, uncompressed name. diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index de6bda6961..de30a08087 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -1,5 +1,5 @@ /* $NetBSD: gzip.c,v 1.67 2004/09/11 11:07:44 dsl Exp $ */ -/* $DragonFly: src/usr.bin/gzip/gzip.c,v 1.6 2006/10/25 08:27:27 swildner Exp $ */ +/* $DragonFly: src/usr.bin/gzip/gzip.c,v 1.7 2007/12/06 19:54:52 hasso Exp $ */ /* * Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green @@ -148,6 +148,7 @@ static int numflag = 6; /* gzip -1..-9 value */ #ifndef SMALL static int fflag; /* force mode */ +static int kflag; /* don't delete input files */ static int nflag; /* don't save name/timestamp */ static int Nflag; /* don't restore name/timestamp */ static int qflag; /* quiet mode */ @@ -224,6 +225,7 @@ static const struct option longopts[] = { { "uncompress", no_argument, 0, 'd' }, { "force", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, + { "keep", no_argument, 0, 'k' }, { "list", no_argument, 0, 'l' }, { "no-name", no_argument, 0, 'n' }, { "name", no_argument, 0, 'N' }, @@ -277,7 +279,7 @@ main(int argc, char **argv) #ifdef SMALL #define OPT_LIST "cdhHltV123456789" #else -#define OPT_LIST "cdfhHlnNqrS:tvV123456789" +#define OPT_LIST "cdfhHklnNqrS:tvV123456789" #endif while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) { @@ -304,6 +306,9 @@ main(int argc, char **argv) case 'f': fflag = 1; break; + case 'k': + kflag = 1; + break; case 'n': nflag = 1; Nflag = 0; @@ -1075,6 +1080,9 @@ unlink_input(const char *file, struct stat *sb) { struct stat nsb; + if (kflag) + return; + if (stat(file, &nsb) != 0) /* Must be gone alrady */ return; @@ -1678,7 +1686,7 @@ handle_dir(char *dir) path_argv[0] = dir; path_argv[1] = 0; - fts = fts_open(path_argv, FTS_PHYSICAL, NULL); + fts = fts_open(path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL); if (fts == NULL) { warn("couldn't fts_open %s", dir); return; @@ -1696,7 +1704,7 @@ handle_dir(char *dir) maybe_warn("%s", entry->fts_path); continue; case FTS_F: - handle_file(entry->fts_name, entry->fts_statp); + handle_file(entry->fts_path, entry->fts_statp); } } (void)fts_close(fts); @@ -1846,14 +1854,17 @@ usage(void) fprintf(stderr, "%s\n", gzip_version); fprintf(stderr, - "usage: %s [-" OPT_LIST "] [ [ ...]]\n" -#ifndef SMALL +#ifdef SMALL + "usage: %s [-" OPT_LIST "] [ [ ...]]\n", +#else + "usage: %s [-123456789acdfhklLNnqrtVv] [-S .suffix] [ [ ...]]\n" " -c --stdout write to stdout, keep original files\n" " --to-stdout\n" " -d --decompress uncompress files\n" " --uncompress\n" " -f --force force overwriting & compress links\n" " -h --help display this help\n" + " -k --keep don't delete input files during operation\n" " -n --no-name don't save original file name or time stamp\n" " -N --name save or restore original file name and time stamp\n" " -q --quiet output no warnings\n" @@ -1866,8 +1877,6 @@ usage(void) " -1 --fast fastest (worst) compression\n" " -2 .. -8 set compression level\n" " -9 --best best (slowest) compression\n", -#else - , #endif getprogname()); exit(0);