]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Move some list_file() checks to args_parse().
authorJia Tan <jiat0218@gmail.com>
Sat, 21 Oct 2023 14:55:51 +0000 (22:55 +0800)
committerJia Tan <jiat0218@gmail.com>
Mon, 29 Jan 2024 13:40:53 +0000 (21:40 +0800)
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
src/xz/list.c

index e8b07af36d6fa8663273394eb4a39ea0d335fef6..825cf92ec6a5def79e978fbd3c438a78b5f18a5a 100644 (file)
@@ -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
index 9693376016e3f3bac2ce7e0450a428d950e2f15c..869b6f79b9bc9d5b72a393fd35b17beb748773c0 100644 (file)
@@ -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) {