0
1
mirror of https://github.com/golang/go synced 2025-06-09 16:49:31 +00:00

os: skip Root.Chtimes atime check on netbsd, truncate a/mtime on plan9

The NetBSD builder has noatime set on its filesystem.
Skip testing the atime on this builder.

Plan9 has second precision on its atime and mtimes.
Truncate the values passed to Chtimes.

For 

Change-Id: I963e2dd34075a9ba025e80641f0b675d5d912188
Reviewed-on: https://go-review.googlesource.com/c/go/+/659356
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Damien Neil
2025-03-19 16:37:16 -07:00
committed by Gopher Robot
parent f233739850
commit 4bc6c71ee0
2 changed files with 9 additions and 3 deletions

@ -1345,6 +1345,9 @@ var hasNoatime = sync.OnceValue(func() bool {
// but the syscall is OS-specific and is not even wired into Go stdlib.
//
// Only used on NetBSD (which ignores explicit atime updates with noatime).
if runtime.GOOS != "netbsd" {
return false
}
mounts, _ := ReadFile("/proc/mounts")
return bytes.Contains(mounts, []byte("noatime"))
})

@ -449,7 +449,8 @@ func TestRootChtimes(t *testing.T) {
atime: time.Now(),
mtime: time.Time{},
}} {
if runtime.GOOS == "js" {
switch runtime.GOOS {
case "js", "plan9":
times.atime = times.atime.Truncate(1 * time.Second)
times.mtime = times.mtime.Truncate(1 * time.Second)
}
@ -465,8 +466,10 @@ func TestRootChtimes(t *testing.T) {
if got := st.ModTime(); !times.mtime.IsZero() && !got.Equal(times.mtime) {
t.Errorf("after root.Chtimes(%q, %v, %v): got mtime=%v, want %v", test.open, times.atime, times.mtime, got, times.mtime)
}
if got := os.Atime(st); !times.atime.IsZero() && !got.Equal(times.atime) {
t.Errorf("after root.Chtimes(%q, %v, %v): got atime=%v, want %v", test.open, times.atime, times.mtime, got, times.atime)
if !hasNoatime() {
if got := os.Atime(st); !times.atime.IsZero() && !got.Equal(times.atime) {
t.Errorf("after root.Chtimes(%q, %v, %v): got atime=%v, want %v", test.open, times.atime, times.mtime, got, times.atime)
}
}
}
})