rm3.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # exercise another small part of remove.c
  3. # Copyright (C) 2002-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ rm
  16. skip_if_root_
  17. mkdir -p z || framework_failure_
  18. cd z || framework_failure_
  19. touch empty empty-u || framework_failure_
  20. echo not-empty > fu
  21. ln -s empty-f slink
  22. ln -s . slinkdot
  23. mkdir d du || framework_failure_
  24. chmod u-w fu du empty-u || framework_failure_
  25. cd ..
  26. cat <<EOF > in || framework_failure_
  27. y
  28. y
  29. y
  30. y
  31. y
  32. y
  33. y
  34. y
  35. y
  36. EOF
  37. # Both of these should fail.
  38. rm -ir z < in > out 2>&1 || fail=1
  39. # Given input like 'rm: ...? rm: ...? ' (no trailing newline),
  40. # the 'head...' part of the pipeline below removes the trailing space, so
  41. # that sed doesn't have to deal with a line lacking a terminating newline.
  42. # This avoids a bug whereby some vendor-provided (Tru64) versions of sed
  43. # would mistakenly tack a newline onto the end of the output.
  44. tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' |sort > o2
  45. mv o2 out || framework_failure_
  46. sort <<EOF > exp || framework_failure_
  47. rm: descend into directory 'z'
  48. rm: remove regular empty file 'z/empty'
  49. rm: remove write-protected regular file 'z/fu'
  50. rm: remove write-protected regular empty file 'z/empty-u'
  51. rm: remove symbolic link 'z/slink'
  52. rm: remove symbolic link 'z/slinkdot'
  53. rm: remove directory 'z/d'
  54. rm: remove write-protected directory 'z/du'
  55. rm: remove directory 'z'
  56. EOF
  57. compare exp out || fail=1
  58. test -d z && fail=1
  59. Exit $fail