lookup username/group-name for longname
When returning file data, the longname field is assigned fileinfo
formatted as a long list entry (like `ls -l`). This adds username and
groupname lookup to that output instead of just using uid/gid values.
Falls back to uid/gid if there is an issue with the lookup.
diff --git a/server_unix.go b/server_unix.go
index 8d0c138..8f9dd8a 100644
--- a/server_unix.go
+++ b/server_unix.go
@@ -6,7 +6,9 @@
import (
"fmt"
"os"
+ "os/user"
"path"
+ "strconv"
"syscall"
"time"
)
@@ -20,10 +22,21 @@
typeword := runLsTypeWord(dirent)
numLinks := statt.Nlink
uid := statt.Uid
+ usr, err := user.LookupId(strconv.Itoa(int(uid)))
+ var username string
+ if err == nil {
+ username = usr.Username
+ } else {
+ username = fmt.Sprintf("%d", uid)
+ }
gid := statt.Gid
- username := fmt.Sprintf("%d", uid)
- groupname := fmt.Sprintf("%d", gid)
- // TODO FIXME: uid -> username, gid -> groupname lookup for ls -l format output
+ grp, err := user.LookupGroupId(strconv.Itoa(int(gid)))
+ var groupname string
+ if err == nil {
+ groupname = grp.Name
+ } else {
+ groupname = fmt.Sprintf("%d", gid)
+ }
mtime := dirent.ModTime()
monthStr := mtime.Month().String()[0:3]