i-3.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. # Make sure that 'mv file unwritable-file' prompts the user
  3. # and that 'mv -f file unwritable-file' doesn't.
  4. # Copyright (C) 2001-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  16. print_ver_ mv
  17. require_controlling_input_terminal_
  18. skip_if_root_
  19. trap '' TTIN # Ignore SIGTTIN
  20. uname -s | grep 'BSD$' && skip_ 'known spurious failure on *BSD'
  21. touch f g h i || framework_failure_
  22. chmod 0 g i || framework_failure_
  23. ls /dev/stdin >/dev/null 2>&1 \
  24. || skip_ 'there is no /dev/stdin file'
  25. # work around a dash bug when redirecting
  26. # from symlinked ttys in the background
  27. tty=$(readlink -f /dev/stdin)
  28. test -r "$tty" 2>&1 \
  29. || skip_ '/dev/stdin is not readable'
  30. # Terminate any background processes
  31. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  32. mv f g < $tty > out 2>&1 & pid=$!
  33. # Test for the expected prompt; sleep upon non-match.
  34. check_overwrite_prompt()
  35. {
  36. local delay="$1"
  37. case "$(cat out)" in
  38. "mv: replace 'g', overriding mode 0000"*) ;;
  39. *) sleep $delay; return 1;;
  40. esac
  41. }
  42. # Wait for up to 12.7 seconds for the expected prompt.
  43. retry_delay_ check_overwrite_prompt .1 7 || { fail=1; cat out; }
  44. cleanup_
  45. mv -f h i > out 2>&1 || fail=1
  46. test -f i || fail=1
  47. test -f h && fail=1
  48. # Make sure there was no prompt.
  49. case "$(cat out)" in
  50. '') ;;
  51. *) fail=1 ;;
  52. esac
  53. Exit $fail