summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tatje <jan@jnt.io>2024-02-04 18:34:02 +0100
committerGitHub <noreply@github.com>2024-02-04 18:34:02 +0100
commit2007ae51a1cdad2323ffb7453463f0b54bd44caf (patch)
tree5de2916ceac26ba727b3760d0bfa196df3cce1f0
parent8a14749154c2c11fce4fec0188dc204c012bd3e9 (diff)
Fallback to showing UID/GID if user/group lookup fails (#1590)
If you mount a filesystem from another computer then UID/GID might not be mapped to any user. This changes it so that lf shows the UID and GID instead of nothing if user/group lookup fails.
-rw-r--r--os.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/os.go b/os.go
index 0c632af..962bb41 100644
--- a/os.go
+++ b/os.go
@@ -199,8 +199,11 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
func userName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
- if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
+ uid := fmt.Sprint(stat.Uid)
+ if u, err := user.LookupId(uid); err == nil {
return u.Username
+ } else {
+ return uid
}
}
return ""
@@ -208,8 +211,11 @@ func userName(f os.FileInfo) string {
func groupName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
- if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
+ gid := fmt.Sprint(stat.Gid)
+ if g, err := user.LookupGroupId(gid); err == nil {
return g.Name
+ } else {
+ return gid
}
}
return ""