1#!/bin/sh 2# Tests for ln -L/-P. 3 4# Copyright (C) 2009-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_ ln 21 22 23# =================================================== 24# ensure -s silently overrides -L, -P 25touch a || framework_failure_ 26ln -L -s a symlink1 || fail=1 27ln -P -s symlink1 symlink2 || fail=1 28ln -s -L -P symlink2 symlink3 || fail=1 29 30# =================================================== 31# ensure that -L follows symlinks, and overrides -P 32if ln -P -L symlink3 hard-to-a; then 33 ls=$(ls -lG hard-to-a)x 34 case "$ls" in 35 *'hard-to-ax') ;; 36 *'hard-to-a -> '*x) fail=1 ;; 37 *) framework_failure_ ;; 38 esac 39else 40 fail=1 41fi 42 43# =================================================== 44# ensure that -P links (or at least duplicates) symlinks, and overrides -L 45if ln -L -P symlink3 hard-to-3; then 46 ls=$(ls -lG hard-to-3)x 47 case "$ls" in 48 *'hard-to-3 -> symlink2x') ;; 49 *'hard-to-3x') fail=1 ;; 50 *'hard-to-3 -> '*x) fail=1 ;; 51 *) framework_failure_ ;; 52 esac 53else 54 fail=1 55fi 56 57# =================================================== 58# Create a hard link to a dangling symlink. 59ln -s /no-such-dir || framework_failure_ 60ln -L no-such-dir hard-to-dangle 2>err && fail=1 61case $(cat err) in 62 *" failed to access 'no-such-dir'":*) ;; 63 *) fail=1 ;; 64esac 65ln -P no-such-dir hard-to-dangle || fail=1 66 67# =================================================== 68# Create a hard link to a symlink to a directory. 69mkdir d || framework_failure_ 70ln -s d link-to-dir || framework_failure_ 71ln -L link-to-dir hard-to-dir-link 2>err && fail=1 72case $(cat err) in 73 *": link-to-dir: hard link not allowed for directory"*) ;; 74 *) fail=1 ;; 75esac 76ln -P link-to-dir/ hard-to-dir-link 2>err && fail=1 77case $(cat err) in 78 *": link-to-dir/: hard link not allowed for directory"*) ;; 79 *) fail=1 ;; 80esac 81ln -P link-to-dir hard-to-dir-link || fail=1 82 83Exit $fail 84