1#!/bin/sh
2# Make sure we give a sensible diagnostic when a cross-device 'mv'
3# fails, e.g., because the destination cannot be unlinked.
4# This is a bit fragile since it relies on the string used
5# for EPERM: 'permission denied'.
6
7# Copyright (C) 2002-2023 Free Software Foundation, Inc.
8
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
22. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23print_ver_ mv
24skip_if_root_
25cleanup_() { t=$other_partition_tmpdir; chmod -R 700 "$t"; rm -rf "$t"; }
26. "$abs_srcdir/tests/other-fs-tmpdir"
27
28touch k "$other_partition_tmpdir/k" || framework_failure_
29chmod u-w "$other_partition_tmpdir" || framework_failure_
30
31
32mv -f k "$other_partition_tmpdir" 2> out && fail=1
33printf \
34"mv: inter-device move failed: '%s' to '%s';"\
35' unable to remove target: Permission denied\n' \
36  k "$other_partition_tmpdir/k" >exp
37
38# On some (less-compliant) systems, we get EPERM in this case.
39# Accept either diagnostic.
40cat <<EOF > exp2
41mv: cannot move 'k' to '$other_partition_tmpdir/k': Permission denied
42EOF
43
44if cmp out exp >/dev/null 2>&1; then
45  :
46else
47  if cmp out exp2; then
48    :
49  else
50    fail=1
51  fi
52fi
53test $fail = 1 && compare exp out
54
55Exit $fail
56