1#!/bin/sh
2# copy files/directories across file system boundaries
3# and make sure acls are preserved appropriately
4
5# Copyright (C) 2005-2023 Free Software Foundation, Inc.
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
20. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21print_ver_ cp
22
23require_acl_
24
25# Skip this test if cp was built without ACL support:
26grep '^#define USE_ACL 1' $CONFIG_HEADER > /dev/null ||
27  skip_ "insufficient ACL support"
28
29mkdir -p a b || framework_failure_
30touch a/file || framework_failure_
31
32# Ensure that setfacl and getfacl work on this file system.
33skip=no
34acl1=$(cd a && getfacl file) || skip=yes
35setfacl -m user:bin:rw- a/file 2> /dev/null || skip=yes
36test $skip = yes &&
37  skip_ "'.' is not on a suitable file system for this test"
38
39# copy a file without preserving permissions
40cp a/file b/ || fail=1
41acl2=$(cd b && getfacl file) || framework_failure_
42test "$acl1" = "$acl2" || fail=1
43
44# Update with acl set above
45acl1=$(cd a && getfacl file) || framework_failure_
46
47# copy a file, preserving permissions
48cp -p a/file b/ || fail=1
49acl2=$(cd b && getfacl file) || framework_failure_
50test "$acl1" = "$acl2" || fail=1
51
52# copy a file, preserving permissions, with --attributes-only
53echo > a/file || framework_failure_ # add some data
54test -s a/file || framework_failure_
55cp -p --attributes-only a/file b/ || fail=1
56compare /dev/null b/file || fail=1
57acl2=$(cd b && getfacl file) || framework_failure_
58test "$acl1" = "$acl2" || fail=1
59
60Exit $fail
61