Don't read compressed data from a terminal or write it

to a terminal even if --force is specified.

It just seems more reasonable this way.

The new behavior matches bzip2. The old one matched gzip.
This commit is contained in:
Lasse Collin 2010-01-13 19:10:25 +02:00
parent 23ac2c44c3
commit 3ffd5d81a4
2 changed files with 13 additions and 15 deletions

View File

@ -168,8 +168,8 @@ main(int argc, char **argv)
message_set_files(args.arg_count); message_set_files(args.arg_count);
// Refuse to write compressed data to standard output if it is // Refuse to write compressed data to standard output if it is
// a terminal and --force wasn't used. // a terminal.
if (opt_mode == MODE_COMPRESS && !opt_force) { if (opt_mode == MODE_COMPRESS) {
if (opt_stdout || (args.arg_count == 1 if (opt_stdout || (args.arg_count == 1
&& strcmp(args.arg_names[0], "-") == 0)) { && strcmp(args.arg_names[0], "-") == 0)) {
if (is_tty_stdout()) { if (is_tty_stdout()) {
@ -188,16 +188,14 @@ main(int argc, char **argv)
// were given, parse_args() gave us a fake "-" filename. // were given, parse_args() gave us a fake "-" filename.
for (size_t i = 0; i < args.arg_count && !user_abort; ++i) { for (size_t i = 0; i < args.arg_count && !user_abort; ++i) {
if (strcmp("-", args.arg_names[i]) == 0) { if (strcmp("-", args.arg_names[i]) == 0) {
// Processing from stdin to stdout. Unless --force // Processing from stdin to stdout. Check that we
// was used, check that we aren't writing compressed // aren't writing compressed data to a terminal or
// data to a terminal or reading it from terminal. // reading it from a terminal.
if (!opt_force) { if (opt_mode == MODE_COMPRESS) {
if (opt_mode == MODE_COMPRESS) { if (is_tty_stdout())
if (is_tty_stdout())
continue;
} else if (is_tty_stdin()) {
continue; continue;
} } else if (is_tty_stdin()) {
continue;
} }
// It doesn't make sense to compress data from stdin // It doesn't make sense to compress data from stdin

View File

@ -223,8 +223,8 @@ is_tty_stdin(void)
const bool ret = isatty(STDIN_FILENO); const bool ret = isatty(STDIN_FILENO);
if (ret) if (ret)
message_error(_("Compressed data not read from a terminal " message_error(_("Compressed data cannot be read from "
"unless `--force' is used.")); "a terminal"));
return ret; return ret;
} }
@ -236,8 +236,8 @@ is_tty_stdout(void)
const bool ret = isatty(STDOUT_FILENO); const bool ret = isatty(STDOUT_FILENO);
if (ret) if (ret)
message_error(_("Compressed data not written to a terminal " message_error(_("Compressed data cannot be written to "
"unless `--force' is used.")); "a terminal"));
return ret; return ret;
} }