Download this file
| 1 | //go:build unix |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "io/fs" |
| 7 | "syscall" |
| 8 | ) |
| 9 | |
| 10 | // fileOwner reports a file's owning uid and gid. Split by build tag because |
| 11 | // internal/host is linked into the CLI, which people run on Macs and Windows, |
| 12 | // and syscall.Stat_t does not exist everywhere — the gate cross-compiles all |
| 13 | // five targets for exactly this reason. |
| 14 | func fileOwner(fi fs.FileInfo) (uid, gid int, ok bool) { |
| 15 | st, ok := fi.Sys().(*syscall.Stat_t) |
| 16 | if !ok { |
| 17 | return 0, 0, false |
| 18 | } |
| 19 | return int(st.Uid), int(st.Gid), true |
| 20 | } |
| 21 | |
| 22 | // fileInode reports a file's device and inode, so a cache can tell a file |
| 23 | // replaced at the same path from the one it hashed. Same split as fileOwner. |
| 24 | func fileInode(fi fs.FileInfo) (dev, ino uint64, ok bool) { |
| 25 | st, ok := fi.Sys().(*syscall.Stat_t) |
| 26 | if !ok { |
| 27 | return 0, 0, false |
| 28 | } |
| 29 | return uint64(st.Dev), uint64(st.Ino), true |
| 30 | } |
| 31 | |