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 8803735
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ 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 {
return u.Username
} else {
return fmt.Sprintf("%d", stat.Uid)
}
}
return ""
Expand All @@ -210,6 +212,8 @@ 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 {
return g.Name
} else {
return fmt.Sprintf("%d", stat.Gid)
}
}
return ""
Expand Down

0 comments on commit 8803735

Please sign in to comment.