From 2f012cb3ea55fd11a7401d23af2f6f90cc978a4a Mon Sep 17 00:00:00 2001 From: Peter Hyman Date: Wed, 19 Jun 2019 05:36:21 -0500 Subject: [PATCH] Fix to allow override of compression set in lrzip.conf --- main.c | 52 +++++++++++++++++++++++++++++----------------------- util.c | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/main.c b/main.c index 6466df4..f3391a8 100644 --- a/main.c +++ b/main.c @@ -308,6 +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 */ struct timeval start_time, end_time; struct sigaction handler; double seconds,total_time; // for timers @@ -342,19 +343,44 @@ int main(int argc, char *argv[]) /* Get Preloaded Defaults from lrzip.conf * Look in ., $HOME/.lrzip/, /etc/lrzip. * If LRZIP=NOCONFIG is set, then ignore config + * If lrzip.conf sets a compression mode, options_file will be true. + * This will allow for a test to permit an override of compression mode. + * If there is an override, then all compression settings will be reset + * and command line switches will prevail, including for --lzma. */ eptr = getenv("LRZIP"); if (eptr == NULL) - read_config(control); + options_file = read_config(control); else if (!strstr(eptr,"NOCONFIG")) - read_config(control); + 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) */ + while ((c = getopt_long(argc, argv, compat ? coptions : loptions, long_options, &i)) != -1) { switch (c) { case 'b': + case 'g': + case 'l': + case 'n': + case 'z': if (control->flags & FLAG_NOT_LZMA) failure("Can only use one of -l, -b, -g, -z or -n\n"); - control->flags |= FLAG_BZIP2_COMPRESS; + /* Select Compression Mode */ + if (c == 'b') + control->flags |= FLAG_BZIP2_COMPRESS; + else if (c == 'g') + control->flags |= FLAG_ZLIB_COMPRESS; + else if (c == 'l') + control->flags |= FLAG_LZO_COMPRESS; + else if (c == 'n') + control->flags |= FLAG_NO_COMPRESS; + else if (c == 'z') + control->flags |= FLAG_ZPAQ_COMPRESS; + break; + case '/': /* LZMA Compress selected */ + control->flags &= ~FLAG_NOT_LZMA; /* clear alternate compression flags */ break; case 'c': if (compat) { @@ -380,11 +406,6 @@ int main(int argc, char *argv[]) case 'f': control->flags |= FLAG_FORCE_REPLACE; break; - case 'g': - if (control->flags & FLAG_NOT_LZMA) - failure("Can only use one of -l, -b, -g, -z or -n\n"); - control->flags |= FLAG_ZLIB_COMPRESS; - break; case 'h': case '?': usage(compat); @@ -405,11 +426,6 @@ int main(int argc, char *argv[]) case 'K': control->flags |= FLAG_KEEP_BROKEN; break; - case 'l': - if (control->flags & FLAG_NOT_LZMA) - failure("Can only use one of -l, -b, -g, -z or -n\n"); - control->flags |= FLAG_LZO_COMPRESS; - break; case 'L': if (compat) { license(); @@ -422,11 +438,6 @@ int main(int argc, char *argv[]) case 'm': control->ramsize = atol(optarg) * 1024 * 1024 * 100; break; - case 'n': - if (control->flags & FLAG_NOT_LZMA) - failure("Can only use one of -l, -b, -g, -z or -n\n"); - control->flags |= FLAG_NO_COMPRESS; - break; case 'N': control->nice_val = atoi(optarg); if (control->nice_val < -20 || control->nice_val > 19) @@ -508,11 +519,6 @@ int main(int argc, char *argv[]) if (control->window < 1) failure("Window must be positive\n"); break; - case 'z': - if (control->flags & FLAG_NOT_LZMA) - failure("Can only use one of -l, -b, -g, -z or -n\n"); - control->flags |= FLAG_ZPAQ_COMPRESS; - break; case '1': case '2': case '3': diff --git a/util.c b/util.c index d79125b..a40de7f 100644 --- a/util.c +++ b/util.c @@ -205,7 +205,7 @@ bool read_config(rzip_control *control) fprintf(control->msgout, "Using configuration file /etc/lrzip/lrzip.conf\n"); } if (fp == NULL) - return true; + return false; /* if we get here, we have a file. read until no more. */