From 8eb867e5f06b6f37b3c6dfaf05e17a14f6edd226 Mon Sep 17 00:00:00 2001 From: Peter Hyman Date: Sun, 27 Oct 2019 11:17:46 -0500 Subject: [PATCH] fix to allow compression in lrzip.conf to be overridden by command line choice. --- doc/lrzip.conf.example | 2 +- main.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/lrzip.conf.example b/doc/lrzip.conf.example index 3edee3a..7eaa0d9 100644 --- a/doc/lrzip.conf.example +++ b/doc/lrzip.conf.example @@ -13,7 +13,7 @@ # Use -U setting, Unlimited ram. Yes or No # UNLIMITED = NO # Compression Method, rzip, gzip, bzip2, lzo, or lzma (default), or zpaq. (-n -g -b -l --lzma -z) -# If specified here, command line options not usable. +# May be overriden by command line compression choice. # COMPRESSIONMETHOD = lzma # Perform LZO Test. Default = YES (-T ) # LZOTEST = NO diff --git a/main.c b/main.c index f3391a8..9b5f7db 100644 --- a/main.c +++ b/main.c @@ -308,7 +308,7 @@ static const char *coptions = "bcCdefghHikKlLnN:o:O:p:PrS:tTUm:vVw:z?123456789"; int main(int argc, char *argv[]) { bool lrzcat = false, compat = false, recurse = false; - bool options_file = false; /* for environment and tracking of compression setting */ + bool options_file = false, conf_file_compression_set = false; /* for environment and tracking of compression setting */ struct timeval start_time, end_time; struct sigaction handler; double seconds,total_time; // for timers @@ -353,10 +353,8 @@ int main(int argc, char *argv[]) options_file = read_config(control); else if (!strstr(eptr,"NOCONFIG")) options_file = read_config(control); - if (options_file) - if (control->flags & FLAG_NOT_LZMA) /* if compression set in conf file */ - control->flags &= ~FLAG_NOT_LZMA; /* clear compression flags (LZMA now default) */ - + if (options_file && (control->flags & FLAG_NOT_LZMA)) /* if some compression set in lrzip.conf */ + conf_file_compression_set = true; /* need this to allow command line override */ while ((c = getopt_long(argc, argv, compat ? coptions : loptions, long_options, &i)) != -1) { switch (c) { @@ -365,9 +363,13 @@ int main(int argc, char *argv[]) case 'l': case 'n': case 'z': - if (control->flags & FLAG_NOT_LZMA) + /* If some compression was chosen in lrzip.conf, allow this one time + * because conf_file_compression_set will be true + */ + if ((control->flags & FLAG_NOT_LZMA) && conf_file_compression_set == false) failure("Can only use one of -l, -b, -g, -z or -n\n"); /* Select Compression Mode */ + control->flags &= ~FLAG_NOT_LZMA; /* must clear all compressions first */ if (c == 'b') control->flags |= FLAG_BZIP2_COMPRESS; else if (c == 'g') @@ -378,6 +380,8 @@ int main(int argc, char *argv[]) control->flags |= FLAG_NO_COMPRESS; else if (c == 'z') control->flags |= FLAG_ZPAQ_COMPRESS; + /* now FLAG_NOT_LZMA will evaluate as true */ + conf_file_compression_set = false; break; case '/': /* LZMA Compress selected */ control->flags &= ~FLAG_NOT_LZMA; /* clear alternate compression flags */