summaryrefslogtreecommitdiff
path: root/tests/mv/part-symlink
blob: 098fe762876c4215e2345566cd006aab5e79757e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
# make sure cp and mv can handle many combinations of local and
# other-partition regular/symlink'd files.

if test "$VERBOSE" = yes; then
  set -x
  mv --version
  cp --version
fi

pwd=`pwd`
tmp=part-sl.$$
trap 'status=$?; cd $pwd; rm -rf $tmp $other_partition_tmpdir && exit $status' 0
trap '(exit $?); exit' 1 2 13 15

pwd_tmp=$pwd/$tmp

. $srcdir/setup
. $srcdir/../envvar-check

if test -z "$other_partition_tmpdir"; then
  (exit 77); exit
fi

framework_failure=0
mkdir $tmp || framework_failure=1
cd $tmp || framework_failure=1

if test $framework_failure = 1; then
  echo 'failure in testing framework'
  exit 1
fi

fail=0

# Four cases:
# local regular file w/symlink on another partition
#   (loc_reg, rem_sl)
#   (rem_sl, loc_reg)
# local symlink to regular file on another partition
#   (loc_sl, rem_reg)
#   (rem_reg, loc_sl)

# Exercise those four cases for each of
# cp and mv, with lots of combinations of options.
# For now, just --rem and without.

actual=actual-$$
expected=expected-$$

exec 1> $actual

# FIXME: This should be bigger: like more than 8k
contents=XYZ

loc_reg=loc_reg
loc_sl=loc_sl
rem_reg=$other_partition_tmpdir/rem_reg
rem_sl=$other_partition_tmpdir/rem_sl

for copy in cp mv; do
  for args in \
      'loc_reg rem_sl' \
      'rem_sl loc_reg' \
      'loc_sl rem_reg' \
      'rem_reg loc_sl' \
      ; do
    for options in '' --rem '--rem -d' '--rem -b'; do
      case "$options" in *--rem*) test $copy = mv && continue;; esac
      rm -rf dir || fail=1
      rm -f $other_partition_tmpdir/rem_reg || fail=1
      rm -f $other_partition_tmpdir/rem_sl || fail=1
      mkdir dir || fail=1
      cd dir || fail=1
      case "$args" in *loc_reg*) reg_abs="`pwd`/$loc_reg" ;; esac
      case "$args" in *rem_reg*) reg_abs=$rem_reg ;; esac
      case "$args" in *loc_sl*) slink=$loc_sl ;; esac
      case "$args" in *rem_sl*) slink=$rem_sl ;; esac

      echo $contents > $reg_abs || fail=1
      ln -nsf $reg_abs $slink || fail=1
      actual_args=`echo $args|sed 's,^,$,;s/ / $/'`
      actual_args=`eval echo $actual_args`

      (
	(
	  # echo 1>&2 cp $options $args
	  $copy $options $actual_args 2>.err
	  copy_status=$?
	  echo $copy_status $copy $options $args

	  # Normalize the program name in the error output,
	  # and put brackets around the output.
	  test -s .err &&
	    cp --backup .err /tmp
	  test -s .err && {
	    echo '[' | tr -d '\012'
	    sed 's/^[^:][^:]*\(..\):/\1:/;s,'$other_partition_tmpdir/,, .err
	    echo ']' | tr -d '\012'
	    }
	  # Strip off all but the file names.
	  ls="`ls -lG --ignore=.err . \
	      | sed \
		  -e '/^total /d' \
		  -e s,$other_partition_tmpdir/,, \
		  -e s,$pwd_tmp/,, \
		  -e 's/^...............................................//'`"
	  ls2="`cd $other_partition_tmpdir && ls -lG --ignore=.err . \
	      | sed \
		  -e '/^total /d' \
		  -e s,$other_partition_tmpdir/,, \
		  -e s,$pwd_tmp/,, \
		  -e 's/^...............................................//'`"
	  echo "($ls) ($ls2)"

	  # If the command failed, then it must not have changed the files.
	  if test $copy_status != 0; then
	    for f in $actual_args; do
	      case "`cat $f`" in
		"$contents") ;;
		*) echo $copy FAILED;;
	      esac
	    done
	  fi

	  if test $copy = cp; then
	    # Make sure the original is unchanged and that
	    # the destination is a copy.
	    for f in $actual_args; do
	      if test -f $f; then
		if test $copy_status != 0; then
		  test
		fi
		case "`cat $f`" in
		  "$contents") ;;
		  *) echo $copy FAILED;;
		esac
	      else
		echo symlink-loop
	      fi
	    done
	  fi
	) | tr '\012' ' '
	echo
      ) | sed 's/  *$//'
      cd ..
    done
    echo
  done
done

test $fail = 1 &&
  { (exit $?); exit; }

cat <<\EOF > $expected

EOF

# Uncomment this if you see a failure and want to try to diagnose it.
diff -u $expected $actual 1>&2

cmp $expected $actual

(exit $?); exit