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.
This commit is contained in:
Jia Tan 2023-10-21 22:55:51 +08:00
parent d6d1e40f19
commit 882aad963e
2 changed files with 8 additions and 4 deletions

View File

@ -786,6 +786,14 @@ args_parse(args_info *args, int argc, char **argv)
if (opt_mode != MODE_COMPRESS) if (opt_mode != MODE_COMPRESS)
message_fatal(_("Decompression support was disabled " message_fatal(_("Decompression support was disabled "
"at build time")); "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 #endif
#ifdef HAVE_LZIP_DECODER #ifdef HAVE_LZIP_DECODER

View File

@ -1276,10 +1276,6 @@ list_totals(void)
extern void extern void
list_file(const char *filename) 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); message_filename(filename);
if (filename == stdin_filename) { if (filename == stdin_filename) {