1#!/bin/sh
2# Test "mv" with special files.
3
4# Copyright (C) 1998-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_ mv
21cleanup_() { rm -rf "$other_partition_tmpdir"; }
22. "$abs_srcdir/tests/other-fs-tmpdir"
23
24null=mv-null
25dir=mv-dir
26
27rm -f $null || framework_failure_
28mknod $null p || framework_failure_
29test -p $null || framework_failure_
30mkdir -p $dir/a/b/c $dir/d/e/f || framework_failure_
31touch $dir/a/b/c/file1 $dir/d/e/f/file2 || framework_failure_
32
33# We used to...
34# exit 77 here to indicate that we couldn't run the test.
35# At least running on SunOS 4.1.4, using a directory NFS mounted
36# from an OpenBSD system, the above mknod fails.
37# It's not worth making an exception any more.
38
39mv --verbose $null $dir "$other_partition_tmpdir" > out || fail=1
40# Make sure the files are gone.
41test -p $null && fail=1
42test -d $dir && fail=1
43# Make sure they were moved.
44test -p "$other_partition_tmpdir/$null" || fail=1
45test -d "$other_partition_tmpdir/$dir/a/b/c" || fail=1
46
47# POSIX says rename (A, B) can succeed if A and B are on different file systems,
48# so ignore chatter about when files are removed and copied rather than renamed.
49sed "
50  /^removed /d
51  s,renamed ,,
52  s,copied ,,
53  s,$other_partition_tmpdir,XXX,
54  s,created directory 'XXX/\(.*\)','\1' -> 'XXX/\1',
55" out | sort > out2
56
57cat <<EOF | sort > exp
58'$null' -> 'XXX/$null'
59'$dir' -> 'XXX/$dir'
60'$dir/a' -> 'XXX/$dir/a'
61'$dir/a/b' -> 'XXX/$dir/a/b'
62'$dir/a/b/c' -> 'XXX/$dir/a/b/c'
63'$dir/a/b/c/file1' -> 'XXX/$dir/a/b/c/file1'
64'$dir/d' -> 'XXX/$dir/d'
65'$dir/d/e' -> 'XXX/$dir/d/e'
66'$dir/d/e/f' -> 'XXX/$dir/d/e/f'
67'$dir/d/e/f/file2' -> 'XXX/$dir/d/e/f/file2'
68EOF
69
70compare exp out2 || fail=1
71
72# cd "$other_partition_tmpdir"
73# ls -l -A -R "$other_partition_tmpdir"
74
75Exit $fail
76