1#!/bin/sh
2# Ensure that ls --file-type does not call stat unnecessarily.
3# Also check for the dtype-related (and fs-type dependent) bug
4# in coreutils-6.0 that made ls -CF columns misaligned.
5
6# Copyright (C) 2006-2023 Free Software Foundation, Inc.
7
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
21# The trick is to create an un-stat'able symlink and to see if ls
22# can report its type nonetheless, using dirent.d_type.
23
24. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
25print_ver_ ls
26
27# Skip this test unless "." is on a file system with useful d_type info.
28# FIXME: This uses "ls -p" to decide whether to test "ls" with other options,
29# but if ls's d_type code is buggy then "ls -p" might be buggy too.
30mkdir -p c/d || framework_failure_
31chmod a-x c || framework_failure_
32if test "X$(ls -p c 2>&1)" != Xd/; then
33  skip_ "'.' is not on a suitable file system for this test"
34fi
35
36mkdir d || framework_failure_
37ln -s / d/s || framework_failure_
38chmod 600 d || framework_failure_
39
40mkdir -p e/a2345 e/b || framework_failure_
41chmod 600 e || framework_failure_
42
43
44ls --file-type d > out || fail=1
45cat <<\EOF > exp || framework_failure_
46s@
47EOF
48
49compare exp out || fail=1
50
51# Check for the ls -CF misaligned-columns bug:
52ls -CF e > out || fail=1
53
54# coreutils-6.0 would print two spaces after the first slash,
55# rather than the appropriate TAB.
56printf 'a2345/\tb/\n' > exp || framework_failure_
57
58compare exp out || fail=1
59
60Exit $fail
61