-
Notifications
You must be signed in to change notification settings - Fork 328
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. This patch fixes the failing utimens tests.
- Loading branch information
Showing
3 changed files
with
62 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,40 @@ | ||
// Copyright 2018 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 converts time.Time to syscall.Timeval | ||
func timeToTimeval(t *time.Time) 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 | ||
var tv syscall.Timeval | ||
tv.Usec = int32(t.Nanosecond() / 1000) | ||
tv.Sec = t.Unix() | ||
return tv | ||
} | ||
|
||
// Fill converts a and m to a syscall.Timeval slice that can be passed | ||
// to syscall.Utimes. Missing values (if any) are taken from attr | ||
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 | ||
} |