summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS9
-rw-r--r--src/ls.c12
-rwxr-xr-xtests/ls/dangle10
3 files changed, 18 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index f1f73472d..e7e4ddccf 100644
--- a/NEWS
+++ b/NEWS
@@ -18,12 +18,9 @@ GNU coreutils NEWS -*- outline -*-
ls -LR exits with status 2, not 0, when it encounters a cycle
- ls -Li is now consistent with ls -Lil in printing "?", not "0" as the
- inode of a dangling symlink.
-
- ls -Li no longer relies on unspecified behavior of stat/lstat.
- Before this change, "ls -Li dangling-symlink" would mistakenly
- print the inode number of the symlink under some conditions.
+ ls -is is now consistent with ls -lis in ignoring values returned
+ from a failed stat/lstat. For example ls -Lis now prints "?", not "0",
+ for the inode number and allocated size of a dereferenced dangling symlink.
** Portability
diff --git a/src/ls.c b/src/ls.c
index 801e717c6..30df92c1a 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4016,8 +4016,9 @@ print_file_name_and_frills (const struct fileinfo *f, size_t start_col)
if (print_block_size)
printf ("%*s ", format == with_commas ? 0 : block_size_width,
- human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
- ST_NBLOCKSIZE, output_block_size));
+ ! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
+ ST_NBLOCKSIZE, output_block_size));
if (print_scontext)
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
@@ -4234,9 +4235,10 @@ length_of_file_name_and_frills (const struct fileinfo *f)
if (print_block_size)
len += 1 + (format == with_commas
- ? strlen (human_readable (ST_NBLOCKS (f->stat), buf,
- human_output_opts, ST_NBLOCKSIZE,
- output_block_size))
+ ? strlen (! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf,
+ human_output_opts, ST_NBLOCKSIZE,
+ output_block_size))
: block_size_width);
if (print_scontext)
diff --git a/tests/ls/dangle b/tests/ls/dangle
index 6abad9213..687d3dfba 100755
--- a/tests/ls/dangle
+++ b/tests/ls/dangle
@@ -28,7 +28,8 @@ mkdir -p dir/sub || framework_failure
ln -s dir slink-to-dir || framework_failure
mkdir d || framework_failure
ln -s no-such d/dangle || framework_failure
-echo '? dangle' > subdir_exp || framework_failure
+printf '? dangle\n' > subdir_Li_exp || framework_failure
+printf 'total 0\n? dangle\n' > subdir_Ls_exp || framework_failure
fail=0
@@ -56,6 +57,11 @@ compare out exp || fail=1
# Ensure that ls -Li prints "?" as the inode of a dangling symlink.
rm -f out
ls -Li d > out 2>/dev/null && fail=1
-compare out subdir_exp || fail=1
+compare out subdir_Li_exp || fail=1
+
+# Ensure that ls -Ls prints "?" as the allocation of a dangling symlink.
+rm -f out
+ls -Ls d > out 2>/dev/null && fail=1
+compare out subdir_Ls_exp || fail=1
Exit $fail