You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
APFS in Mac OS X 10.13 supports nanosecond timestamps. os.Stat returns the full resolution timestamps, but os.Chtimes is unable to set them, since it doesn't call the right system call. This means it is impossible to "round trip" a file and preserve these details.
I have a change that implements this, by calling setattrlist in syscall_darwin.go. This works on at least Mac OS X 10.11.6 (it drops the resolution), and on Mac OS X 10.13 on APFS, which I will submit shortly.
What version of Go are you using (go version)?
go version go1.9.2 darwin/amd64
go version devel +018642d Wed Nov 1 14:35:30 2017 +0000 darwin/amd64
What did you do?
The following code on Mac OS X creates a temporary file, displays its ModTime, then sets it to a time in the past, and prints the new ModTime. Ideally, the full nanosecond resolution should be displayed and preserved in all cases.
package main
import (
"fmt""os""runtime""time"
)
funcmain() {
fmt.Println("go version:", runtime.Version())
// create a new fileconstfilePath="example"f, err:=os.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
iferr!=nil {
panic(err)
}
f.Close()
stat, err:=os.Stat(filePath)
iferr!=nil {
panic(err)
}
fmt.Println("mtime after creation:", stat.ModTime())
// change the time with nanosecond precisiont:=time.Unix(1509480275, 123456789)
fmt.Println("setting mtime to:", t)
err=os.Chtimes(filePath, t, t)
iferr!=nil {
panic(err)
}
stat, err=os.Stat(filePath)
iferr!=nil {
panic(err)
}
fmt.Println("mtime after set:", stat.ModTime())
}
Output on Mac OS X 10.13
When the file is first created, it has nanosecond precision. After the call to Chtimes, the mtime is truncated to microseconds, since Darwin calls utimes which takes a struct timeval with microsecond precision:
go version: go1.9.2
mtime after creation: 2017-11-01 12:53:21.849659583 -0400 EDT
setting mtime to: 2017-10-31 16:04:35.123456789 -0400 EDT
mtime after set: 2017-10-31 16:04:35.123457 -0400 EDT
The fixed version calls setattrlist which takes a struct timespec with nanosecond resolution:
go version: devel +018642d Wed Nov 1 14:35:30 2017 +0000
mtime after creation: 2017-11-01 12:53:27.388937366 -0400 EDT
setting mtime to: 2017-10-31 16:04:35.123456789 -0400 EDT
mtime after set: 2017-10-31 16:04:35.123456789 -0400 EDT
Output on Mac OS X 10.11
With or without the case is the same: HFS only has seconds resolution, so the timestamps are truncated.
go version: go1.9.2
mtime after creation: 2017-11-01 12:03:12 -0400 EDT
setting mtime to: 2017-10-31 16:04:35.123456789 -0400 EDT
mtime after set: 2017-10-31 16:04:35 -0400 EDT
go version: devel +018642d Wed Nov 1 14:35:30 2017 +0000
mtime after creation: 2017-11-01 12:07:38 -0400 EDT
setting mtime to: 2017-10-31 16:04:35.123456789 -0400 EDT
mtime after set: 2017-10-31 16:04:35 -0400 EDT
The text was updated successfully, but these errors were encountered:
Change https://golang.org/cl/74952 mentions this issue: syscall: use setattrlist for UtimesNano on Darwin for ns resolution
ianlancetaylor
changed the title
os.Chtimes: Support nanosecond resolution on Mac OS X
os: Chtimes: support nanosecond resolution on Mac OS X
Nov 1, 2017
APFS in Mac OS X 10.13 supports nanosecond timestamps.
os.Stat
returns the full resolution timestamps, butos.Chtimes
is unable to set them, since it doesn't call the right system call. This means it is impossible to "round trip" a file and preserve these details.I have a change that implements this, by calling
setattrlist
insyscall_darwin.go
. This works on at least Mac OS X 10.11.6 (it drops the resolution), and on Mac OS X 10.13 on APFS, which I will submit shortly.What version of Go are you using (
go version
)?go version go1.9.2 darwin/amd64
go version devel +018642d Wed Nov 1 14:35:30 2017 +0000 darwin/amd64
What did you do?
The following code on Mac OS X creates a temporary file, displays its ModTime, then sets it to a time in the past, and prints the new ModTime. Ideally, the full nanosecond resolution should be displayed and preserved in all cases.
Output on Mac OS X 10.13
When the file is first created, it has nanosecond precision. After the call to
Chtimes
, the mtime is truncated to microseconds, since Darwin callsutimes
which takes astruct timeval
with microsecond precision:The fixed version calls
setattrlist
which takes astruct timespec
with nanosecond resolution:Output on Mac OS X 10.11
With or without the case is the same: HFS only has seconds resolution, so the timestamps are truncated.
The text was updated successfully, but these errors were encountered: