forked from josch/mmdebstrap
error out if stdout is a tty
This commit is contained in:
parent
117a1591c5
commit
d82afec5de
3 changed files with 21 additions and 2 deletions
|
@ -322,3 +322,5 @@ Modes: fakechroot
|
|||
Test: dev-ptmx
|
||||
Modes: root unshare
|
||||
Needs-QEMU: true
|
||||
|
||||
Test: error-if-stdout-is-tty
|
||||
|
|
|
@ -37,7 +37,8 @@ use Cwd qw(abs_path getcwd);
|
|||
require "syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
|
||||
use Fcntl qw(S_IFCHR S_IFBLK FD_CLOEXEC F_GETFD F_SETFD);
|
||||
use List::Util qw(any none);
|
||||
use POSIX qw(SIGINT SIGHUP SIGPIPE SIGTERM SIG_BLOCK SIG_UNBLOCK strftime);
|
||||
use POSIX
|
||||
qw(SIGINT SIGHUP SIGPIPE SIGTERM SIG_BLOCK SIG_UNBLOCK strftime isatty);
|
||||
use Carp;
|
||||
use Term::ANSIColor;
|
||||
use Socket;
|
||||
|
@ -5126,7 +5127,11 @@ sub main() {
|
|||
$options->{sourceslists} = $sourceslists;
|
||||
}
|
||||
|
||||
if ($options->{target} ne '-') {
|
||||
if ($options->{target} eq '-') {
|
||||
if (POSIX::isatty STDOUT) {
|
||||
error "stdout is a an interactive tty";
|
||||
}
|
||||
} else {
|
||||
my $abs_path = abs_path($options->{target});
|
||||
if (!defined $abs_path) {
|
||||
error "unable to get absolute path of target directory"
|
||||
|
|
12
tests/error-if-stdout-is-tty
Normal file
12
tests/error-if-stdout-is-tty
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
export LC_ALL=C.UTF-8
|
||||
|
||||
ret=0
|
||||
script -qfec "{{ CMD }} --mode={{ MODE }} --variant=apt {{ DIST }} - {{ MIRROR }}" /dev/null || ret=$?
|
||||
if [ "$ret" = 0 ]; then
|
||||
echo expected failure but got exit $ret >&2
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in a new issue