2007-06-10 14:56:39 +02:00
|
|
|
#!/bin/sh
|
2007-11-16 09:31:15 +01:00
|
|
|
# Ensure that cp works as documented, when the destination is a dangling symlink
|
2007-06-10 14:56:39 +02:00
|
|
|
|
2025-01-01 09:14:56 +00:00
|
|
|
# Copyright (C) 2007-2025 Free Software Foundation, Inc.
|
2007-06-10 14:56:39 +02:00
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2007-06-10 14:56:39 +02:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
2007-06-10 14:56:39 +02:00
|
|
|
# (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
|
2017-09-19 01:13:23 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2007-06-10 14:56:39 +02:00
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2010-11-17 21:35:31 +01:00
|
|
|
print_ver_ cp
|
2007-06-10 14:56:39 +02:00
|
|
|
|
2011-08-04 20:52:31 +02:00
|
|
|
ln -s no-such dangle || framework_failure_
|
|
|
|
|
echo hi > f || framework_failure_
|
|
|
|
|
echo hi > exp || framework_failure_
|
2012-01-07 17:43:50 +01:00
|
|
|
echo "cp: not writing through dangling symlink 'dangle'" \
|
2011-08-04 20:52:31 +02:00
|
|
|
> exp-err || framework_failure_
|
2007-06-10 14:56:39 +02:00
|
|
|
|
|
|
|
|
|
2007-11-16 09:31:15 +01:00
|
|
|
# Starting with 6.9.90, this usage fails, by default:
|
2018-05-03 21:19:15 -07:00
|
|
|
for opt in '' '-f'; do
|
2018-05-15 23:41:36 -07:00
|
|
|
returns_ 1 cp $opt f dangle > err 2>&1 || fail=1
|
2018-05-03 21:19:15 -07:00
|
|
|
compare exp-err err || fail=1
|
|
|
|
|
test -f no-such && fail=1
|
|
|
|
|
done
|
2007-11-16 09:31:15 +01:00
|
|
|
|
2018-05-15 23:41:36 -07:00
|
|
|
|
2007-11-16 09:31:15 +01:00
|
|
|
# But you can set POSIXLY_CORRECT to get the historical behavior.
|
2008-08-13 10:40:58 +02:00
|
|
|
env POSIXLY_CORRECT=1 cp f dangle > out 2>&1 || fail=1
|
2007-06-10 14:56:39 +02:00
|
|
|
cat no-such >> out || fail=1
|
2011-11-22 10:08:04 +01:00
|
|
|
compare exp out || fail=1
|
2007-06-10 14:56:39 +02:00
|
|
|
|
2018-05-15 23:41:36 -07:00
|
|
|
|
|
|
|
|
# Starting with 8.30 we treat ELOOP as existing and so
|
|
|
|
|
# remove the symlink
|
|
|
|
|
ln -s loop loop || framework_failure_
|
|
|
|
|
cp -f f loop > err 2>&1 || fail=1
|
|
|
|
|
compare /dev/null err || fail=1
|
|
|
|
|
compare exp loop || fail=1
|
|
|
|
|
test -f loop || fail=1
|
|
|
|
|
|
2008-09-07 10:31:27 +02:00
|
|
|
Exit $fail
|