| 1 | // +build !windows |
| 2 | |
| 3 | package os |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "os" |
| 8 | "syscall" |
| 9 | ) |
| 10 | |
| 11 | // Returns the UID for a file. |
| 12 | func GetFileUID(fi os.FileInfo) (int, error) { |
| 13 | st, ok := fi.Sys().(*syscall.Stat_t) |
| 14 | if !ok { |
| 15 | return 0, fmt.Errorf("unknown file info type: %T", fi.Sys()) |
| 16 | } |
| 17 | |
| 18 | return int(st.Uid), nil |
| 19 | } |
| 20 | |
| 21 | // Returns the GID for a file. |
| 22 | func GetFileGID(fi os.FileInfo) (int, error) { |
| 23 | st, ok := fi.Sys().(*syscall.Stat_t) |
| 24 | if !ok { |
| 25 | return 0, fmt.Errorf("unknown file info type: %T", fi.Sys()) |
| 26 | } |
| 27 | |
| 28 | return int(st.Gid), nil |
| 29 | } |