Skip to content

Commit

Permalink
mem: add getter for UID/GID
Browse files Browse the repository at this point in the history
Since mem.Stat().Sys() always returns nil, there's no
way to determine the user or group ID set by Chown().

One example use case is determining whether a file or
directory is writable by the current user.

Signed-off-by: Dominik Menke <dom@digineo.de>
  • Loading branch information
dmke committed Apr 18, 2022
1 parent 100c9a6 commit 363dd64
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,26 @@ func SetUID(f *FileData, uid int) {
f.Unlock()
}

func GetUID(f *FileData) (uid int) {
f.Lock()
uid = f.uid
f.Unlock()
return
}

func SetGID(f *FileData, gid int) {
f.Lock()
f.gid = gid
f.Unlock()
}

func GetGID(f *FileData) (gid int) {
f.Lock()
gid = f.gid
f.Unlock()
return
}

func GetFileInfo(f *FileData) *FileInfo {
return &FileInfo{f}
}
Expand Down

0 comments on commit 363dd64

Please sign in to comment.