1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-12 02:12:06 +02:00

tests: mv: add checks for cross device handling of special files

* tests/mv/mv-special-2.sh: Add test to ensure we preserve
sparse files, character devices, symlinks, when moving across
file system boundaries.
Addresses https://github.com/coreutils/coreutils/issues/136
This commit is contained in:
Pádraig Brady
2025-12-01 15:03:36 +00:00
parent ffbd8c4878
commit 95b737c835
2 changed files with 63 additions and 0 deletions

View File

@@ -135,6 +135,7 @@ all_root_tests = \
tests/mkdir/smack-root.sh \
tests/mv/hardlink-case.sh \
tests/mv/sticky-to-xpart.sh \
tests/mv/mv-special-2.sh \
tests/rm/fail-2eperm.sh \
tests/rm/no-give-up.sh \
tests/rm/one-file-system.sh \

62
tests/mv/mv-special-2.sh Executable file
View File

@@ -0,0 +1,62 @@
#!/bin/sh
# Ensure that mv works with non standard copies across file systems
# Copyright (C) 2025 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ mv
require_root_
cwd=$(pwd)
cleanup_() { cd /; umount "$cwd/xdev"; }
skip=0
# Mount an ext2 loopback file system at $WHERE
make_fs() {
where="$1"
mkdir "$where" || framework_failure_
fs="$where.bin"
dd if=/dev/zero of="$fs" bs=8192 count=200 > /dev/null 2>&1 || skip=1
mkfs -t ext2 -F "$fs" || skip_ "failed to create ext2 file system"
mount -oloop "$fs" "$where" || skip=1
echo test > "$where"/f && test -s "$where"/f || skip=1
test $skip = 1 && skip_ 'insufficient mount/ext2 support'
}
make_fs xdev
truncate -s 8G huge || framework_failure_
mv --verbose huge xdev &&
returns_ 1 test -e huge &&
test -s xdev/huge || fail=1
mknod devzero c 1 5 || framework_failure_
mv --verbose devzero xdev &&
returns_ 1 test -c devzero &&
test -c xdev/devzero || fail=1
ln -nsf blah blah || framework_failure_
mv --verbose blah xdev &&
returns_ 1 test -L blah &&
test -L xdev/blah || fail=1
Exit $fail