forked from hanwen/go-fuse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
darwin, loopback: emulate UTIME_OMIT
All but the newest MacOS versions (xnu-4570.1.46 / High Sierra) lack utimensat() and UTIME_OMIT, see: https://github.com/apple/darwin-xnu/blame/0a798f6738bc1db01281fc08ae024145e84df927/bsd/sys/stat.h#L537 The UTIME_OMIT value is intepreted literally by MacOS, resulting in all files getting a 1970 timestamp ( rfjakob/gocryptfs#229 ). Emulate UTIME_OMIT by filling in the missing values using an extra GetAttr call. To not duplicate the logic in pathfs and nodefs, an internal "utimens" helper package is created.
- Loading branch information
Showing
3 changed files
with
64 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2016 the Go-FUSE Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package utimens | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
|
||
"github.com/hanwen/go-fuse/fuse" | ||
) | ||
|
||
// timeToTimeval - convert time.Time to syscall.Timeval | ||
// | ||
// Note: This does not use syscall.NsecToTimespec because | ||
// that does not work properly for times before 1970, | ||
// see https://github.com/golang/go/issues/12777 | ||
func timeToTimeval(t *time.Time) syscall.Timeval { | ||
var tv syscall.Timeval | ||
tv.Usec = int32(t.Nanosecond() / 1000) | ||
tv.Sec = t.Unix() | ||
return tv | ||
} | ||
|
||
// Fill - fill the missing timestamp value (if any) from attr, and pack | ||
// both into a syscall.Timeval slice that can be passed to syscall.Utimes() | ||
// or syscall.Futimes(). | ||
func Fill(a *time.Time, m *time.Time, attr *fuse.Attr) []syscall.Timeval { | ||
if a == nil { | ||
a2 := time.Unix(int64(attr.Atime), int64(attr.Atimensec)) | ||
a = &a2 | ||
} | ||
if m == nil { | ||
m2 := time.Unix(int64(attr.Mtime), int64(attr.Mtimensec)) | ||
m = &m2 | ||
} | ||
tv := make([]syscall.Timeval, 2) | ||
tv[0] = timeToTimeval(a) | ||
tv[1] = timeToTimeval(m) | ||
return tv | ||
} |