Skip to content

Commit

Permalink
xz: Move suffix check after stdout mode is detected.
Browse files Browse the repository at this point in the history
This fixes a bug introduced in cc5aa9a
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.
  • Loading branch information
JiaT75 committed Nov 14, 2023
1 parent d4f4a4d commit 837ea40
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/xz/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 837ea40

Please sign in to comment.