mirror of
https://git.tukaani.org/xz.git
synced 2024-04-04 12:36:23 +02:00
xz: Fix suffix check.
The suffix refactor done in 99575947a5
had a small regression where raw format compression to standard out
failed if a suffix was not set. In this case, setting the suffix did
not make sense since a file is not created.
Now, xz should only fail when a suffix is not provided when it is
actually needed.
For instance:
echo "foo" | xz --format=raw --lzma2 | wc -c
does not need a suffix check since it creates no files. But:
xz --format=raw --lzma2 --suffix=.bar foo
Needs the suffix to be set since it must create foo.bar.
This commit is contained in:
parent
84196e8c09
commit
87c956d4c4
1 changed files with 22 additions and 8 deletions
|
@ -718,6 +718,28 @@ args_parse(args_info *args, int argc, char **argv)
|
||||||
if (opt_mode == MODE_COMPRESS && opt_format == FORMAT_AUTO)
|
if (opt_mode == MODE_COMPRESS && opt_format == FORMAT_AUTO)
|
||||||
opt_format = FORMAT_XZ;
|
opt_format = FORMAT_XZ;
|
||||||
|
|
||||||
|
// 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)) {
|
||||||
|
if (args->files_name != NULL)
|
||||||
|
message_fatal(_("With --format=raw, "
|
||||||
|
"--suffix=.SUF is required "
|
||||||
|
"unless writing to stdout"));
|
||||||
|
|
||||||
|
// If all of the filenames provided are "-" (more than one
|
||||||
|
// "-" could be specified) or no filenames are provided,
|
||||||
|
// then we are only going to be writing to standard out.
|
||||||
|
for (int i = optind; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "-") != 0)
|
||||||
|
message_fatal(_("With --format=raw, "
|
||||||
|
"--suffix=.SUF is required "
|
||||||
|
"unless writing to stdout"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compression settings need to be validated (options themselves and
|
// Compression settings need to be validated (options themselves and
|
||||||
// their memory usage) when compressing to any file format. It has to
|
// their memory usage) when compressing to any file format. It has to
|
||||||
// be done also when uncompressing raw data, since for raw decoding
|
// be done also when uncompressing raw data, since for raw decoding
|
||||||
|
@ -727,14 +749,6 @@ args_parse(args_info *args, int argc, char **argv)
|
||||||
&& opt_mode != MODE_LIST))
|
&& opt_mode != MODE_LIST))
|
||||||
coder_set_compression_settings();
|
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 no filenames are given, use stdin.
|
||||||
if (argv[optind] == NULL && args->files_name == NULL) {
|
if (argv[optind] == NULL && args->files_name == NULL) {
|
||||||
// We don't modify or free() the "-" constant. The caller
|
// We don't modify or free() the "-" constant. The caller
|
||||||
|
|
Loading…
Reference in a new issue