Skip to content

Commit e23250d

Browse files
committed
Fixed mtime issue for OSX
1 parent 084eeaf commit e23250d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

third_party/go9p/srv_file.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package go9p
66

77
import (
88
"log"
9+
"runtime"
910
"sync"
1011
"time"
1112
)
@@ -132,7 +133,13 @@ func (f *srvFile) Add(dir *srvFile, name string, uid User, gid Group, mode uint3
132133
f.Qid.Version = 0
133134
f.Qid.Path = qpath
134135
f.Mode = mode
135-
f.Atime = uint32(time.Now().Unix())
136+
// macOS filesystem st_mtime values are only accurate to the second
137+
// without truncating, 9p will invent a changing fractional time #1375
138+
if runtime.GOOS == "darwin" {
139+
f.Atime = uint32(time.Now().Truncate(time.Second).Unix())
140+
} else {
141+
f.Atime = uint32(time.Now().Unix())
142+
}
136143
f.Mtime = f.Atime
137144
f.Length = 0
138145
f.Name = name

third_party/go9p/ufs_darwin.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func (u *Ufs) Wstat(req *SrvReq) {
228228
//at = time.Time(0)//atime(st.Sys().(*syscall.Stat_t))
229229
}
230230
}
231-
e := os.Chtimes(fid.path, at, mt)
231+
// macOS filesystem st_mtime values are only accurate to the second
232+
// this ensures, 9p will only write mtime to the second #1375
233+
e := os.Chtimes(fid.path, at.Truncate(time.Second), mt.Truncate(time.Second))
232234
if e != nil {
233235
req.RespondError(toError(e))
234236
return

0 commit comments

Comments
 (0)