vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Build the tree for Windows and name the platform seams
215f8aebc38e69e621eb6f739e0cfea2ba07fd9a · Keenan Nemetz · 2d ago · parent 416739b1
Build the tree for Windows and name the platform seams `go build` for windows/amd64 failed on five unix syscall uses, and the tree had nowhere to say what a platform can and cannot do. Each unix-only site now lives in a `_unix.go` file with a Windows counterpart: disk capacity through GetDiskFreeSpaceEx, allocated bytes through GetCompressedFileSize, hard-link identity through GetFileInformationByHandle, the runner's cache lock through LockFileEx, a liveness probe through OpenProcess, and a command's process group through a helper that has no group to signal yet. Two sites cannot be ported without weakening them, so they refuse rather than pretend. File modes are a unix control and Windows needs ACLs instead, so `internal/secure` will not create or accept a secret there, and `internal/audit` will not verify a log it cannot check. The front door says the same about exec, which Windows does not have: sshd gets an explanation instead of a process that returns EWINDOWS. A CI step cross-compiles windows/amd64 and vets it, and `go vet` is what type-checks the test files that `go build` skips, so a unix-only call fails a push instead of a port nobody can start. Part of 01M8S9B86B36PE0MY8MMCRCMYA.
internal/storage/storage.go +11−36
| @@ -8,7 +8,6 @@ import ( | |||
| 8 | 8 | "io/fs" | |
| 9 | 9 | "path/filepath" | |
| 10 | 10 | "strings" | |
| 11 | "syscall" | ||
| 12 | 11 | "time" | |
| 13 | 12 | ) | |
| 14 | 13 | ||
| @@ -42,6 +41,15 @@ type Stats struct { | |||
| 42 | 41 | Measured time.Time | |
| 43 | 42 | } | |
| 44 | 43 | ||
| 44 | // fileKey identifies one file in the platform's own terms: a device and inode on | ||
| 45 | // unix, a volume serial and file index on Windows. A platform that cannot report | ||
| 46 | // one counts every name a hard link has, which over-reports rather than loses | ||
| 47 | // bytes. | ||
| 48 | type fileKey struct { | ||
| 49 | dev uint64 | ||
| 50 | ino uint64 | ||
| 51 | } | ||
| 52 | |||
| 45 | 53 | // Measure walks root, deduplicates hard links, and asks the filesystem for its | |
| 46 | 54 | // free space. | |
| 47 | 55 | func Measure(root string) (Stats, error) { | |
| @@ -77,19 +85,14 @@ func Measure(root string) (Stats, error) { | |||
| 77 | 85 | } | |
| 78 | 86 | return err | |
| 79 | 87 | } | |
| 80 | key, linked := fileKeyFor(info) | ||
| 88 | key, linked := fileKeyFor(path, info) | ||
| 81 | 89 | if linked { | |
| 82 | 90 | if seen[key] { | |
| 83 | 91 | return nil | |
| 84 | 92 | } | |
| 85 | 93 | seen[key] = true | |
| 86 | 94 | } | |
| 87 | n := info.Size() | ||
| 88 | if st, ok := info.Sys().(*syscall.Stat_t); ok && st.Blocks > 0 { | ||
| 89 | // Blocks is in 512-byte units, regardless of the filesystem's block | ||
| 90 | // size. It is the allocation the file actually costs. | ||
| 91 | n = st.Blocks * 512 | ||
| 92 | } | ||
| 95 | n := allocatedBytes(path, info) | ||
| 93 | 96 | name := category(path, root) | |
| 94 | 97 | cats[name].Bytes += n | |
| 95 | 98 | cats[name].Files++ | |
| @@ -106,19 +109,6 @@ func Measure(root string) (Stats, error) { | |||
| 106 | 109 | return st, nil | |
| 107 | 110 | } | |
| 108 | 111 | ||
| 109 | type fileKey struct { | ||
| 110 | dev uint64 | ||
| 111 | ino uint64 | ||
| 112 | } | ||
| 113 | |||
| 114 | func fileKeyFor(info fs.FileInfo) (fileKey, bool) { | ||
| 115 | st, ok := info.Sys().(*syscall.Stat_t) | ||
| 116 | if !ok { | ||
| 117 | return fileKey{}, false | ||
| 118 | } | ||
| 119 | return fileKey{dev: uint64(st.Dev), ino: st.Ino}, true | ||
| 120 | } | ||
| 121 | |||
| 122 | 112 | func category(path, root string) string { | |
| 123 | 113 | rel, err := filepath.Rel(root, path) | |
| 124 | 114 | if err != nil { | |
| @@ -145,18 +135,3 @@ func category(path, root string) string { | |||
| 145 | 135 | } | |
| 146 | 136 | return "Other" | |
| 147 | 137 | } | |
| 148 | |||
| 149 | func diskUsage(root string) (Disk, error) { | ||
| 150 | var st syscall.Statfs_t | ||
| 151 | if err := syscall.Statfs(root, &st); err != nil { | ||
| 152 | return Disk{}, err | ||
| 153 | } | ||
| 154 | // Bsize is int64 on Linux and uint32 on Darwin, so it is converted here | ||
| 155 | // rather than used directly; this file is built for both when a release | ||
| 156 | // produces a macOS binary. | ||
| 157 | blockSize := int64(st.Bsize) | ||
| 158 | total := int64(st.Blocks) * blockSize | ||
| 159 | free := int64(st.Bfree) * blockSize | ||
| 160 | available := int64(st.Bavail) * blockSize | ||
| 161 | return Disk{Total: total, Used: total - free, Available: available}, nil | ||
| 162 | } | ||