1#!/bin/sh
2# Make sure cp --attributes-only doesn't truncate existing data
3
4# Copyright 2012-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_ cp
21
22printf '1' > file1 || framework_failure_
23printf '2' > file2 || framework_failure_
24printf '2' > file2.exp || framework_failure_
25
26cp --attributes-only file1 file2 || fail=1
27cmp file2 file2.exp || fail=1
28
29# coreutils v8.32 and before would remove destination files
30# if hardlinked or the source was not a regular file.
31ln file2 link2 || framework_failure_
32cp -a --attributes-only file1 file2 || fail=1
33cmp file2 file2.exp || fail=1
34
35ln -s file1 sym1 || framework_failure_
36returns_ 1 cp -a --attributes-only sym1 file2 || fail=1
37cmp file2 file2.exp || fail=1
38
39# One can still force removal though
40cp -a --remove-destination --attributes-only sym1 file2 || fail=1
41test -L file2 || fail=1
42cmp file1 file2 || fail=1
43
44Exit $fail
45