demo / network-computer
Public
Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.
GitStable demo
README: say this is a copy and where the original is
cde82c2
13 hours, 39 minutes ago
History
files_unix.go · 845 bytes · 39 lines
| 1 | //go:build linux || darwin |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "syscall" |
| 8 | ) |
| 9 | |
| 10 | func freeBytes(dir string) (int64, error) { |
| 11 | var st syscall.Statfs_t |
| 12 | if err := syscall.Statfs(dir, &st); err != nil { |
| 13 | return 0, err |
| 14 | } |
| 15 | return int64(st.Bavail) * int64(st.Bsize), nil |
| 16 | } |
| 17 | |
| 18 | // chownLike gives a received file to whoever owns the directory it lands in |
| 19 | // (the host runs as root; the file belongs to the desk user). |
| 20 | func chownLike(path, dir string) { |
| 21 | if fi, err := os.Stat(dir); err == nil { |
| 22 | if st, ok := fi.Sys().(*syscall.Stat_t); ok { |
| 23 | os.Chown(path, int(st.Uid), int(st.Gid)) |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // ownerGroup is the group of whoever owns dir (the desk user). |
| 29 | func ownerGroup(dir string) (int, bool) { |
| 30 | fi, err := os.Stat(dir) |
| 31 | if err != nil { |
| 32 | return 0, false |
| 33 | } |
| 34 | st, ok := fi.Sys().(*syscall.Stat_t) |
| 35 | if !ok { |
| 36 | return 0, false |
| 37 | } |
| 38 | return int(st.Gid), true |
| 39 | } |