internal/pkg: zero atime and mtime
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m50s
Test / ShareFS (push) Successful in 4m54s
Test / Hpkg (push) Successful in 5m10s
Test / Sandbox (race detector) (push) Successful in 5m16s
Test / Hakurei (push) Successful in 5m36s
Test / Hakurei (race detector) (push) Successful in 7m43s
Test / Flake checks (push) Successful in 1m42s

This is significantly more practical than keeping track of them in directory flattening format and setting this in every non-artifact implementation. Only tarArtifact can have meaningful deterministic checksums that are not zero and zeroing them still keeps autotools happy.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-13 01:28:55 +09:00
parent 156dd767ef
commit 1667df9c43

View File

@@ -19,6 +19,7 @@ import (
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
"unsafe"
"hakurei.app/container/check" "hakurei.app/container/check"
"hakurei.app/message" "hakurei.app/message"
@@ -801,6 +802,33 @@ func removeAll(pathname *check.Absolute) (chmodErr, removeErr error) {
return return
} }
// zeroTimes zeroes atime and mtime for the named file.
func zeroTimes(path string) (err error) {
// include/uapi/linux/fcntl.h
const (
AT_FDCWD = -100
AT_SYMLINK_NOFOLLOW = 0x100
)
_AT_FDCWD := AT_FDCWD
var _p0 *byte
_p0, err = syscall.BytePtrFromString(path)
if err != nil {
return
}
if _, _, errno := syscall.Syscall6(
syscall.SYS_UTIMENSAT,
uintptr(_AT_FDCWD),
uintptr(unsafe.Pointer(_p0)),
uintptr(unsafe.Pointer(new([2]syscall.Timespec))),
AT_SYMLINK_NOFOLLOW,
0, 0,
); errno != 0 {
return os.NewSyscallError("utimensat", errno)
}
return
}
// overrideFileInfo overrides the permission bits of [fs.FileInfo] to 0500 and // overrideFileInfo overrides the permission bits of [fs.FileInfo] to 0500 and
// is the concrete type returned by overrideFile.Stat. // is the concrete type returned by overrideFile.Stat.
type overrideFileInfo struct{ fs.FileInfo } type overrideFileInfo struct{ fs.FileInfo }
@@ -914,6 +942,9 @@ func (c *Cache) Cure(a Artifact) (
checksumLinknamePrefix+checksums, checksumLinknamePrefix+checksums,
pathname.String(), pathname.String(),
) )
if err == nil {
err = zeroTimes(pathname.String())
}
} }
}() }()
@@ -1009,10 +1040,15 @@ func (c *Cache) Cure(a Artifact) (
} }
_, err = w.Write(data) _, err = w.Write(data)
closeErr := w.Close() closeErr := w.Close()
timeErr := zeroTimes(checksumPathname.String())
c.checksumMu.Unlock()
if err == nil {
err = timeErr
}
if err == nil { if err == nil {
err = closeErr err = closeErr
} }
c.checksumMu.Unlock()
return return
} }
@@ -1125,6 +1161,14 @@ func (c *Cache) Cure(a Artifact) (
if err = os.Chmod(t.work.String(), 0700); err != nil { if err = os.Chmod(t.work.String(), 0700); err != nil {
return return
} }
if err = filepath.WalkDir(t.work.String(), func(path string, _ fs.DirEntry, err error) error {
if err != nil {
return err
}
return zeroTimes(path)
}); err != nil {
return
}
c.checksumMu.Lock() c.checksumMu.Lock()
if err = os.Rename( if err = os.Rename(
t.work.String(), t.work.String(),