Skip to content

Commit bdd798e

Browse files
committed
BUG: Read choice only from the controlling terminal, not the previous pipe step stdout
1 parent 7a1b81f commit bdd798e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

myba.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ _encrypt_file () {
175175
compress_if_text |
176176
_encrypt "$_plain_path" > "$ENC_REPO/$_enc_path"
177177
}
178+
_bind_tty_fd7 () { : < /dev/tty && exec 7< /dev/tty || exec 7< /dev/null; } # Fd 7 used in _decrypt_file
178179
_decrypt_file () {
179180
_enc_path="$1"
180181
_plain_path="$2"
181182
# Check if the plain file already exists
183+
[ ! -d "/proc/$$" ] || [ -e "/proc/$$/fd/7" ] # Assert fd-7 is available
182184
if [ -f "$WORK_TREE/$_plain_path" ] && [ -z "${YES_OVERWRITE:-}" ]; then
183185
warn "WARNING: File '$WORK_TREE/$_plain_path' exists. Overwrite? [y/N]"
184-
read _choice
186+
read _choice <&7
185187
case "$_choice" in [Yy]*) ;; *) warn "Skipping '$WORK_TREE/$_plain_path'"; return 0 ;; esac
186188
fi
187189
decrypted_tmpfile="$(_mktemp)"
@@ -306,6 +308,7 @@ cmd_decrypt () {
306308
fi
307309
else
308310
quiet _trap_append "git_enc checkout --force master" INT HUP TERM EXIT
311+
_bind_tty_fd7
309312
git_enc rev-list --reverse master |
310313
while IFS= _read_vars _enc_commit; do
311314
# shellcheck disable=SC2154
@@ -602,6 +605,7 @@ cmd_checkout() {
602605
git_enc sparse-checkout reapply
603606

604607
_ask_pw
608+
_bind_tty_fd7
605609
_parallelize 0 2 _checkout_file < "$working_manifest"
606610
fi
607611
}

smoke-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ title 'Ensure restoration script is present in the encrypted repo'
7777
stat "$WORK_TREE/.myba/_encrypted/myba.sh"
7878
title 'No overwrite existing file unless forced'
7979
myba checkout "foo/.dotfile"
80-
if myba checkout "foo/.dotfile"; then exit 2; fi
80+
if setsid myba checkout "foo/.dotfile"; then exit 2; fi
8181
YES_OVERWRITE=1 myba checkout "foo/.dotfile"
8282
unset YES_OVERWRITE # Fix for buggy macOS shell
8383

0 commit comments

Comments
 (0)