From c9863e0e606d724fdebc583568c78004673d1d6d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 20 Feb 2011 23:02:15 +1100 Subject: [PATCH] Change default behaviour to deleting broken or damaged files that occur by interrupting lrzip or that fail integrity testing. Implement the -k option to optionally keep broken or damaged files. --- main.c | 6 +++++- rzip.h | 2 ++ util.c | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index e0a0dcf..cf8b14f 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,7 @@ static void usage(void) print_output(" -i show compressed file information\n"); print_output(" -H display md5 Hash integrity information\n"); print_output(" -c check integrity of file written on decompression\n"); + print_output(" -k keep broken or damaged output files\n"); print_output("\nIf no filenames or \"-\" is specified, stdin/out will be used.\n"); } @@ -606,7 +607,7 @@ int main(int argc, char *argv[]) else if (!strstr(eptr,"NOCONFIG")) read_config(&control); - while ((c = getopt(argc, argv, "L:hdS:tVvDfqo:w:nlbMUO:T:N:p:gziHc")) != -1) { + while ((c = getopt(argc, argv, "L:hdS:tVvDfqo:w:nlbMUO:T:N:p:gziHck")) != -1) { switch (c) { case 'L': control.compression_level = atoi(optarg); @@ -727,6 +728,9 @@ int main(int argc, char *argv[]) control.flags |= FLAG_CHECK; control.flags |= FLAG_HASH; break; + case 'k': + control.flags |= FLAG_KEEP_BROKEN; + break; case 'h': usage(); return -1; diff --git a/rzip.h b/rzip.h index 3862a5b..d083a4d 100644 --- a/rzip.h +++ b/rzip.h @@ -215,6 +215,7 @@ static inline i64 get_ram(void) #define FLAG_HASH (1 << 17) #define FLAG_MD5 (1 << 18) #define FLAG_CHECK (1 << 19) +#define FLAG_KEEP_BROKEN (1 << 20) #define FLAG_VERBOSE (FLAG_VERBOSITY | FLAG_VERBOSITY_MAX) #define FLAG_NOT_LZMA (FLAG_NO_COMPRESS | FLAG_LZO_COMPRESS | FLAG_BZIP2_COMPRESS | FLAG_ZLIB_COMPRESS | FLAG_ZPAQ_COMPRESS) @@ -241,6 +242,7 @@ static inline i64 get_ram(void) #define HASH_CHECK (control.flags & FLAG_HASH) #define HAS_MD5 (control.flags & FLAG_MD5) #define CHECK_FILE (control.flags & FLAG_CHECK) +#define KEEP_BROKEN (control.flags & FLAG_KEEP_BROKEN) #define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5)) diff --git a/util.c b/util.c index 3bb61bb..9501f51 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,6 @@ /* - Copyright (C) 2006-2010 Con Kolivas + Copyright (C) 2006-2011 Con Kolivas + Copyright (C) 2008 Peter Hyman Copyright (C) 1998 Andrew Tridgell This program is free software; you can redistribute it and/or modify @@ -42,7 +43,7 @@ void fatal(const char *format, ...) } /* Delete temporary files generated for testing or faking stdio */ - if (TEST_ONLY || STDOUT) + if (TEST_ONLY || STDOUT || !KEEP_BROKEN) unlink(control.outfile); if (DECOMPRESS && STDIN) @@ -56,7 +57,7 @@ void fatal(const char *format, ...) void sighandler() { /* Delete temporary files generated for testing or faking stdio */ - if (TEST_ONLY || STDOUT) + if (TEST_ONLY || STDOUT || !KEEP_BROKEN) unlink(control.outfile); if (DECOMPRESS && STDIN)