From 882aad963ef09ec13ad20d11af4a3c1be4868eb0 Mon Sep 17 00:00:00 2001 From: Jia Tan Date: Sat, 21 Oct 2023 22:55:51 +0800 Subject: [PATCH] xz: Move some list_file() checks to args_parse(). The checks enforce that list mode will only run on .xz files. The opt_format is only set during argument parsing and will not change after. So we only need to check this once instead of every call to list_file(). Additionally, this will cause the error to be detected slightly earlier. --- src/xz/args.c | 8 ++++++++ src/xz/list.c | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/xz/args.c b/src/xz/args.c index e8b07af3..825cf92e 100644 --- a/src/xz/args.c +++ b/src/xz/args.c @@ -786,6 +786,14 @@ args_parse(args_info *args, int argc, char **argv) if (opt_mode != MODE_COMPRESS) message_fatal(_("Decompression support was disabled " "at build time")); +#else + // List mode is only available when decoders are enabled and is + // only valid with .xz files. + if (opt_mode == MODE_LIST + && opt_format != FORMAT_XZ + && opt_format != FORMAT_AUTO) + message_fatal(_("--list works only on .xz files " + "(--format=xz or --format=auto)")); #endif #ifdef HAVE_LZIP_DECODER diff --git a/src/xz/list.c b/src/xz/list.c index 96933760..869b6f79 100644 --- a/src/xz/list.c +++ b/src/xz/list.c @@ -1276,10 +1276,6 @@ list_totals(void) extern void list_file(const char *filename) { - if (opt_format != FORMAT_XZ && opt_format != FORMAT_AUTO) - message_fatal(_("--list works only on .xz files " - "(--format=xz or --format=auto)")); - message_filename(filename); if (filename == stdin_filename) {