Files
xarmian 48c3ca066c fix(test): test temp dirs stop leaking into /tmp (BUG-3412) (#1786)
* fix(test): template and fixture temp dirs no longer leak into /tmp (BUG-3412)

The store test templates are named for the owning pid, and each build
first removes the template dirs of processes that are gone (and pid-less
legacy dirs over a day old), so a test binary killed before TestMain's
Cleanup no longer leaves its template on the tmpfs for good. The fence
source tests remove their fixture dirs when the file finishes.

Claude-Session: https://claude.ai/code/session_01Q9WssCjFuHjSfLABoW4tmS

* fix(test): never sweep pid-less template dirs; age proves no owner gone (codex r1 on BUG-3412)

Claude-Session: https://claude.ai/code/session_01Q9WssCjFuHjSfLABoW4tmS
2026-10-05 04:50:02 -04:00

24 lines
580 B
Go

//go:build !windows
package testtmp
import (
"errors"
"os"
"syscall"
)
// processAlive reports whether pid names a running process. EPERM means it
// exists under another user, which counts as alive.
func processAlive(pid int) bool {
err := syscall.Kill(pid, 0)
return err == nil || errors.Is(err, syscall.EPERM)
}
// ownedByMe reports whether this user owns the directory, so a sweep never
// touches another account's files in a shared temp dir.
func ownedByMe(info os.FileInfo) bool {
st, ok := info.Sys().(*syscall.Stat_t)
return ok && int(st.Uid) == os.Getuid()
}