dcantrell / bsdutils

Alternative to GNU coreutils using software from FreeBSD
Other
169 stars 9 forks source link

ls(1): fall back to numeric IDs in long form if needed #26

Closed q66 closed 3 years ago

q66 commented 3 years ago

This better matches the behavior of other ls(1) implementations as it will not just fail but fall back to actual numeric IDs if the real names are not known. This can happen e.g. in a chroot or a namespace or any place where you have files or directories with UIDs/GIDs that do not match what is in the local database.

q66 commented 3 years ago

e.g. this:

q66@rimi: /home/q66/cports-orig$ python3 cbuild.py chroot
OK: 261 distinct packages available
/tmp$ ls -l /
total 144
-rw-r--r--    1 root   root      0 Sep 10 02:48 .cbuild_chroot_configured
-rw-r--r--    1 root   root      8 Sep 10 02:48 .cbuild_chroot_init
lrwxrwxrwx    1 root   root      7 Sep 10 02:48 bin -> usr/bin
drwxr-xr-x    3 root   root   4096 Aug 11 22:07 binpkgs
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 boot
drwxr-xr-x   18 root   root   4096 Sep 18 17:48 builddir
drwxr-xr-x   19 root   root   4096 Sep 18 03:37 ccache
drwxr-xr-x    2 root   root   4096 Sep 18 17:48 destdir
drwxr-xr-x    4 root   root    340 Sep 18 17:49 dev
drwxr-xr-x   10 root   root   4096 Sep 18 17:48 etc
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 home
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 host
lrwxrwxrwx    1 root   root      7 Sep 10 02:48 lib -> usr/lib
lrwxrwxrwx    1 root   root      7 Sep 10 02:48 lib64 -> usr/lib
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 media
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 mnt
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 opt
dr-xr-xr-x  802 65534  65534     0 Aug  8 17:26 proc
drwxr-x---    2 root   root   4096 Sep 10 02:48 root
drwxr-xr-x    3 root   root   4096 Sep 10 02:48 run
lrwxrwxrwx    1 root   root      7 Sep 10 02:48 sbin -> usr/bin
drwxr-xr-x  128 root   root   4096 Sep  7 21:02 sources
drwxr-xr-x    2 root   root   4096 Sep 10 02:48 sys
drwxr-xr-x    2 root   root     40 Sep 18 17:49 tmp
drwxr-xr-x    9 root   root   4096 Sep 10 02:48 usr
drwxr-xr-x   10 root   root   4096 Sep 10 02:48 var
/tmp$ exit

is running in a Linux namespace, and the ownership of the /proc directory actually breaks ls -l output without this commit.

q66 commented 3 years ago

Hm, from the output I also notice that it's showing hidden files by default too, which it shouldn't. I'll fix that in a separate PR

q66 commented 3 years ago

okay, nevermind that one, that's a bug in musl-fts (FTS_SEEDOT is not handled right)

q66 commented 3 years ago

okay, there is actually no bug, i just forgot i was defaulting to 0 UID/GID in the user namespace when using chroot, and running ls as root implies -A :) so this PR is good as it is

dcantrell commented 3 years ago

Yep, looks good to me. Thanks.