2 # Ensure that using `cp --preserve=link' to copy hard-linked arguments
3 # onto existing destinations works, even when one of the link operations fails.
4 # This bug was fixed in coreutils-4.5.9.
5 # To exercise this bug is non-trivial:
6 # Set-up requires at least three hard-linked files. In copying them,
7 # while preserving links, the initial copy must succeed, the attempt
8 # to create the second file via `link' must fail, and the final `link'
9 # (to create the third) must succeed. Before the corresponding fix,
10 # the first and third destination files would not be linked.
12 # Note that this is nominally a test of `cp', yet it is in the tests/mv
13 # directory, because it requires use of the --preserve=link option that
14 # mv enables by default.
16 if test "$VERBOSE" = yes; then
21 . $srcdir/../envvar-check
22 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
25 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
26 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
27 trap '(exit $?); exit $?' 1 2 13 15
30 mkdir -p $tmp || framework_failure=1
31 cd $tmp || framework_failure=1
32 mkdir -p x dst/x || framework_failure=1
33 touch dst/x/b || framework_failure=1
35 touch a || framework_failure=1
36 ln a x/b || framework_failure=1
37 ln a c || framework_failure=1
39 if test $framework_failure = 1; then
40 echo "$0: failure in testing framework" 1>&2
46 # ======================================
47 # This must fail -- because x/b cannot be unlinked.
48 cp --preserve=link --parents a x/b c dst 2> /dev/null && fail=1
50 # Source files must remain.
56 # Three destination files must exist.
61 # The i-node numbers of a and c must be the same.
62 ia=`ls -i a|sed 's/ a$//'`
63 ic=`ls -i c|sed 's/ c$//'`
64 test $ia = $ic || fail=1
66 # The i-node number of x/b must be different.
67 ib=`ls -i x/b|sed 's/ x.b$//'`
68 test $ia = $ib && fail=1
70 (exit $fail); exit $fail