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