aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-11-14 20:27:46 +0800
committerJia Tan <jiat0218@gmail.com>2023-11-14 20:27:46 +0800
commit837ea40b1c9d4998cac4500b55171bf33e0c31a6 (patch)
tree20456aa583a83cd47bf508174aba00a2fa8b9c23
parentxz: Detect when all data will be written to standard out earlier. (diff)
downloadxz-837ea40b1c9d4998cac4500b55171bf33e0c31a6.tar.xz
xz: Move suffix check after stdout mode is detected.
This fixes a bug introduced in cc5aa9ab138beeecaee5a1e81197591893ee9ca0 when the suffix check was initially moved. This caused a situation that previously worked: echo foo | xz -Fraw --lzma1 | wc -c to fail because the old code knew that this would write to standard out so a suffix was not needed.
-rw-r--r--src/xz/args.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/xz/args.c b/src/xz/args.c
index e3cddda3..bdeaed67 100644
--- a/src/xz/args.c
+++ b/src/xz/args.c
@@ -820,14 +820,6 @@ args_parse(args_info *args, int argc, char **argv)
&& opt_mode != MODE_LIST))
coder_set_compression_settings();
- // If raw format is used and a custom suffix is not provided,
- // then only stdout mode can be used when compressing or decompressing.
- if (opt_format == FORMAT_RAW && !suffix_is_set() && !opt_stdout
- && (opt_mode == MODE_COMPRESS
- || opt_mode == MODE_DECOMPRESS))
- message_fatal(_("With --format=raw, --suffix=.SUF is "
- "required unless writing to stdout"));
-
// If no filenames are given, use stdin.
if (argv[optind] == NULL && args->files_name == NULL) {
// We don't modify or free() the "-" constant. The caller
@@ -863,6 +855,14 @@ args_parse(args_info *args, int argc, char **argv)
opt_stdout = i == args->arg_count;
}
+ // If raw format is used and a custom suffix is not provided,
+ // then only stdout mode can be used when compressing or decompressing.
+ if (opt_format == FORMAT_RAW && !suffix_is_set() && !opt_stdout
+ && (opt_mode == MODE_COMPRESS
+ || opt_mode == MODE_DECOMPRESS))
+ message_fatal(_("With --format=raw, --suffix=.SUF is "
+ "required unless writing to stdout"));
+
return;
}