瀏覽代碼

unix: fix TestUtimesNanoAt for filesystems with 1-second resolution time stamps

Some file systems don't support sub-second time stamp resolution. Handle
these correctly by only checking nanoseconds in case Mtim.Nsec is zero.

Fixes golang/go#26034

Change-Id: I1ab400b8e09b5cfdac6b70a33f676770a48180b1
Reviewed-on: https://go-review.googlesource.com/120816
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: jimmy frasche <soapboxcicero@gmail.com>
Tobias Klauser 7 年之前
父節點
當前提交
c4afb3effa
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      unix/syscall_linux_test.go

+ 8 - 2
unix/syscall_linux_test.go

@@ -142,8 +142,14 @@ func TestUtimesNanoAt(t *testing.T) {
 	}
 
 	// Only check Mtim, Atim might not be supported by the underlying filesystem
-	if st.Mtim != ts[1] {
-		t.Errorf("UtimesNanoAt: wrong mtime: %v", st.Mtim)
+	expected := ts[1]
+	if st.Mtim.Nsec == 0 {
+		// Some filesystems only support 1-second time stamp resolution
+		// and will always set Nsec to 0.
+		expected.Nsec = 0
+	}
+	if st.Mtim != expected {
+		t.Errorf("UtimesNanoAt: wrong mtime: expected %v, got %v", expected, st.Mtim)
 	}
 }