Fix #104191: Manager build error on ARM64

Reimplement the `touch()` function on Linux to avoid depending on the
`syscall` package, and use the `sys/unix` package instead. This is
slightly higher level, and seems to build on AMD64 and ARM64.
This commit is contained in:
Sybren A. Stüvel 2023-05-01 17:55:54 +02:00
parent bbeefd4bfa
commit ebf4021da2

View File

@ -23,21 +23,21 @@
package touch package touch
import ( import (
"syscall" "os"
"unsafe"
"golang.org/x/sys/unix"
) )
// touch is the same as syscall.utimes, but passes NULL as timestamp pointer (instead of a // touch uses uni.UtimesNano() in order to pass the special 'now' timestamps
// pointer to a concrete time). // available in that package.
func touch(path string) (err error) { func touch(path string) (err error) {
var _p0 *byte now := unix.Timespec{
_p0, err = syscall.BytePtrFromString(path) Sec: 0,
if err != nil { Nsec: unix.UTIME_NOW,
return
} }
_, _, e1 := syscall.Syscall(syscall.SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(0), 0) utimes := []unix.Timespec{now, now}
if e1 != 0 { if e := unix.UtimesNano(path, utimes); e != nil {
err = syscall.Errno(e1) return &os.PathError{Op: "chtimes", Path: path, Err: e}
} }
return return nil
} }