1#!/bin/sh 2# Make sure ls properly handles dangling symlinks vs. ls's -L, -H, options. 3 4# Copyright (C) 2003-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_ ls 21 22LS_MINOR_PROBLEM=1 23LS_FAILURE=2 24 25ln -s no-such-file dangle || framework_failure_ 26mkdir -p dir/sub || framework_failure_ 27ln -s dir slink-to-dir || framework_failure_ 28mkdir d || framework_failure_ 29ln -s no-such d/dangle || framework_failure_ 30printf '? dangle\n' > subdir_Li_exp || framework_failure_ 31printf 'total 0\n? dangle\n' > subdir_Ls_exp || framework_failure_ 32 33# This must exit nonzero. 34returns_ $LS_FAILURE ls -L dangle > /dev/null 2>&1 || fail=1 35# So must this. 36returns_ $LS_FAILURE ls -H dangle > /dev/null 2>&1 || fail=1 37 38# This must exit successfully. 39ls dangle >> out || fail=1 40 41ls slink-to-dir >> out 2>&1 || fail=1 42ls -H slink-to-dir >> out 2>&1 || fail=1 43ls -L slink-to-dir >> out 2>&1 || fail=1 44 45cat <<\EOF > exp 46dangle 47sub 48sub 49sub 50EOF 51 52compare exp out || fail=1 53 54# Ensure that ls -Li prints "?" as the inode of a dangling symlink. 55rm -f out 56returns_ $LS_MINOR_PROBLEM ls -Li d > out 2>/dev/null || fail=1 57compare subdir_Li_exp out || fail=1 58 59# Ensure that ls -Ls prints "?" as the allocation of a dangling symlink. 60rm -f out 61returns_ $LS_MINOR_PROBLEM ls -Ls d > out 2>/dev/null || fail=1 62compare subdir_Ls_exp out || fail=1 63 64Exit $fail 65