fix: [y/N] is asked on the terminal, not on stdin
confirm() returned yes whenever stdin was not a tty, so `dotup < /dev/null` in a terminal drew the picker on /dev/tty and then installed without asking. It now opens /dev/tty the way cmd_pick does and reads the answer there; it auto-approves only when no terminal exists at all. pty test plus a mutation (ISSUE-9).
This commit is contained in:
1 parent
91a1224a5e
commit
f8b17a79d3
3 files changed
+47
-2
No files matched your search
@@ -0,0 +1,11 @@
|
|||||||
|
# what: confirm() decides on `[ -t 0 ]` again instead of opening /dev/tty
|
||||||
|
# why: `dotup < /dev/null` in a terminal picks, then installs with no [y/N] (ISSUE-9)
|
||||||
|
# kills: stdin /dev/null with a terminal still asks [y/N]
|
||||||
|
# run: unit
|
||||||
|
<<<OLD
|
||||||
|
(exec 3</dev/tty) 2>/dev/null || return 0
|
||||||
|
printf '\n install? [y/N] ' >&2
|
||||||
|
<<<NEW
|
||||||
|
[ -t 0 ] || return 0
|
||||||
|
printf '\n install? [y/N] ' >&2
|
||||||
|
<<<END
|
||||||
@@ -1299,6 +1299,36 @@ else
|
|||||||
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
printf '\n\033[1m[y/N] means what it says — asked on the terminal\033[0m\n'
|
||||||
|
# ISSUE-9. confirm() asked `[ -t 0 ]`, so `dotup < /dev/null` in a terminal
|
||||||
|
# drew the picker on /dev/tty, accepted, and installed without ever asking.
|
||||||
|
# The pty is the terminal; stdin is /dev/null, as in the report.
|
||||||
|
if command -v python3 >/dev/null; then
|
||||||
|
ttyrun() { # ttyrun <script> -- dotup's default run on a pty, stdin /dev/null
|
||||||
|
python3 ./ptydrive.py --timeout 30 --script "$1" -- \
|
||||||
|
/usr/bin/env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C \
|
||||||
|
TMPDIR="$SB/tmp" DOTUP_STATE="$SB/.config/dotfiles" \
|
||||||
|
DOTUP_MANIFEST="$M" DOTUP_TEST_LOG="$LOG" \
|
||||||
|
"$BOXPATH/sh" -c 'exec "$0" "$@" </dev/null' "$BOXPATH/sh" $D 2>&1 \
|
||||||
|
| tr -d '\r' | plain
|
||||||
|
}
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
||||||
|
pick core/ripgrep
|
||||||
|
printf 'expect install\\? \\[y/N\\]\nsend n\nexpect nothing installed\n' > "$SB/no.expect"
|
||||||
|
out=$(ttyrun "$SB/no.expect" || true)
|
||||||
|
has "stdin /dev/null with a terminal still asks [y/N]" "install? [y/N]" "$out"
|
||||||
|
is "…and n installs nothing" "0" \
|
||||||
|
"$(grep -c 'apt-get install' "$LOG" || true)"
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
||||||
|
pick core/ripgrep
|
||||||
|
printf 'expect install\\? \\[y/N\\]\nsend y\n' > "$SB/yes.expect"
|
||||||
|
out=$(ttyrun "$SB/yes.expect" || true)
|
||||||
|
is "…and y, typed on the terminal, installs" "1" \
|
||||||
|
"$(grep -c 'apt-get install.* ripgrep' "$LOG" || true)"
|
||||||
|
else
|
||||||
|
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
||||||
|
fi
|
||||||
|
|
||||||
printf '\n\033[1mthe private tier — the three guards, exercised\033[0m\n'
|
printf '\n\033[1mthe private tier — the three guards, exercised\033[0m\n'
|
||||||
# Each of these is one line of dotup, and each of them survived being INVERTED:
|
# Each of these is one line of dotup, and each of them survived being INVERTED:
|
||||||
# the suite only ever checked that the words were in the file. What matters is
|
# the suite only ever checked that the words were in the file. What matters is
|
||||||
|
|||||||
@@ -1681,9 +1681,13 @@ cmd_pick() {
|
|||||||
|
|
||||||
confirm() {
|
confirm() {
|
||||||
[ "$ASSUME_YES" -eq 0 ] || return 0
|
[ "$ASSUME_YES" -eq 0 ] || return 0
|
||||||
[ -t 0 ] || return 0
|
# The same question cmd_pick asks, for the same reason (ISSUE-9): `[ -t 0 ]`
|
||||||
|
# was false for `dotup < /dev/null` in a terminal, so the picker drew on
|
||||||
|
# /dev/tty and then the install ran with no [y/N] at all. Auto-yes only
|
||||||
|
# when there is no terminal anywhere; otherwise ask on the terminal.
|
||||||
|
(exec 3</dev/tty) 2>/dev/null || return 0
|
||||||
printf '\n install? [y/N] ' >&2
|
printf '\n install? [y/N] ' >&2
|
||||||
a=''; IFS= read -r a || a=''
|
a=''; IFS= read -r a < /dev/tty || a=''
|
||||||
case $a in y|Y|yes|YES) return 0 ;; *) say " nothing installed."; return 1 ;; esac
|
case $a in y|Y|yes|YES) return 0 ;; *) say " nothing installed."; return 1 ;; esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user