Skip to content

Commit

Permalink
Fallback to showing UID/GID if user/group lookup fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jantatje committed Jan 31, 2024
1 parent 8a14749 commit 30e5cc5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,23 @@ 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 ""
}

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 ""
Expand Down

0 comments on commit 30e5cc5

Please sign in to comment.