]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: mv: ensure ownership preserved when copying
authorPádraig Brady <P@draigBrady.com>
Thu, 11 Dec 2025 20:17:20 +0000 (20:17 +0000)
committerPádraig Brady <P@draigBrady.com>
Thu, 11 Dec 2025 20:32:41 +0000 (20:32 +0000)
* tests/mv/meta-to-xpart.sh: Add new test.
* tests/local.mk: Reference new test.

tests/local.mk
tests/mv/meta-to-xpart.sh [new file with mode: 0755]

index 955de4e22aa4b2cc5c08a37d1f698bac13eb2e45..f84dd4f4190ccbe3b5537427b1180bca36c0455c 100644 (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/meta-to-xpart.sh                    \
   tests/mv/mv-special-2.sh                     \
   tests/rm/fail-2eperm.sh                      \
   tests/rm/no-give-up.sh                       \
diff --git a/tests/mv/meta-to-xpart.sh b/tests/mv/meta-to-xpart.sh
new file mode 100755 (executable)
index 0000000..c9d3b7a
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+# A cross-partition move of a file should maintain user and permissions
+
+# 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_
+
+cleanup_() { rm -rf "$other_partition_tmpdir"; }
+. "$abs_srcdir/tests/other-fs-tmpdir"
+
+touch non-root-owned || framework_failure_
+chown "$NON_ROOT_USERNAME" non-root-owned ||
+  skip_ "can't chown to $NON_ROOT_USERNAME"
+# Also check setuid bit, since it's security sensitive
+# and also dependent on correct order of meta data update.
+chmod u+s non-root-owned ||
+  skip_ "can't set setuid bit"
+
+mv non-root-owned "$other_partition_tmpdir" || fail=1
+
+test -u "$other_partition_tmpdir"/non-root-owned || fail=1
+test $(stat -c %U "$other_partition_tmpdir"/non-root-owned) = \
+  "$NON_ROOT_USERNAME" || fail=1
+
+Exit $fail