Commit f9bfdb9c authored by Adam Goode's avatar Adam Goode Committed by Han-Wen Nienhuys

Standardize on time.Time for all times in the API

parent 44c3ce73
...@@ -78,7 +78,7 @@ type FsNode interface { ...@@ -78,7 +78,7 @@ type FsNode interface {
Chmod(file File, perms uint32, context *Context) (code Status) Chmod(file File, perms uint32, context *Context) (code Status)
Chown(file File, uid uint32, gid uint32, context *Context) (code Status) Chown(file File, uid uint32, gid uint32, context *Context) (code Status)
Truncate(file File, size uint64, context *Context) (code Status) Truncate(file File, size uint64, context *Context) (code Status)
Utimens(file File, atime int64, mtime int64, context *Context) (code Status) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status)
StatFs() *StatfsOut StatFs() *StatfsOut
} }
...@@ -105,7 +105,7 @@ type FileSystem interface { ...@@ -105,7 +105,7 @@ type FileSystem interface {
// These should update the file's ctime too. // These should update the file's ctime too.
Chmod(name string, mode uint32, context *Context) (code Status) Chmod(name string, mode uint32, context *Context) (code Status)
Chown(name string, uid uint32, gid uint32, context *Context) (code Status) Chown(name string, uid uint32, gid uint32, context *Context) (code Status)
Utimens(name string, AtimeNs int64, MtimeNs int64, context *Context) (code Status) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status)
Truncate(name string, size uint64, context *Context) (code Status) Truncate(name string, size uint64, context *Context) (code Status)
...@@ -179,7 +179,7 @@ type File interface { ...@@ -179,7 +179,7 @@ type File interface {
GetAttr(out *Attr) Status GetAttr(out *Attr) Status
Chown(uid uint32, gid uint32) Status Chown(uid uint32, gid uint32) Status
Chmod(perms uint32) Status Chmod(perms uint32) Status
Utimens(atimeNs int64, mtimeNs int64) Status Utimens(atime *time.Time, mtime *time.Time) Status
} }
// The result of Read is an array of bytes, but for performance // The result of Read is an array of bytes, but for performance
......
...@@ -71,48 +71,18 @@ func (a *Attr) IsSymlink() bool { return (uint32(a.Mode) & syscall.S_IFMT) == sy ...@@ -71,48 +71,18 @@ func (a *Attr) IsSymlink() bool { return (uint32(a.Mode) & syscall.S_IFMT) == sy
// IsSocket reports whether the FileInfo describes a socket. // IsSocket reports whether the FileInfo describes a socket.
func (a *Attr) IsSocket() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFSOCK } func (a *Attr) IsSocket() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFSOCK }
func (a *Attr) Atimens() int64 {
return int64(1e9*a.Atime) + int64(a.Atimensec)
}
func (a *Attr) Mtimens() int64 {
return int64(1e9*a.Mtime) + int64(a.Mtimensec)
}
func (a *Attr) Ctimens() int64 {
return int64(1e9*a.Ctime) + int64(a.Ctimensec)
}
func (a *Attr) SetNs(atimens int64, mtimens int64, ctimens int64) {
if atimens >= 0 {
a.Atime = uint64(atimens / 1e9)
a.Atimensec = uint32(atimens % 1e9)
}
if mtimens >= 0 {
a.Mtime = uint64(mtimens / 1e9)
a.Mtimensec = uint32(mtimens % 1e9)
}
if atimens >= 0 {
a.Ctime = uint64(ctimens / 1e9)
a.Ctimensec = uint32(ctimens % 1e9)
}
}
func (a *Attr) SetTimes(access *time.Time, mod *time.Time, chstatus *time.Time) { func (a *Attr) SetTimes(access *time.Time, mod *time.Time, chstatus *time.Time) {
if access != nil { if access != nil {
atimens := access.UnixNano() a.Atime = uint64(access.Unix())
a.Atime = uint64(atimens / 1e9) a.Atimensec = uint32(access.Nanosecond())
a.Atimensec = uint32(atimens % 1e9)
} }
if mod != nil { if mod != nil {
mtimens := mod.UnixNano() a.Mtime = uint64(mod.Unix())
a.Mtime = uint64(mtimens / 1e9) a.Mtimensec = uint32(mod.Nanosecond())
a.Mtimensec = uint32(mtimens % 1e9)
} }
if chstatus != nil { if chstatus != nil {
ctimens := chstatus.UnixNano() a.Ctime = uint64(chstatus.Unix())
a.Ctime = uint64(ctimens / 1e9) a.Ctimensec = uint32(chstatus.Nanosecond())
a.Ctimensec = uint32(ctimens % 1e9)
} }
} }
......
package fuse package fuse
import () import (
"time"
)
// DefaultFileSystem // DefaultFileSystem
func (fs *DefaultFileSystem) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *DefaultFileSystem) GetAttr(name string, context *Context) (*Attr, Status) {
...@@ -89,7 +91,7 @@ func (fs *DefaultFileSystem) Create(name string, flags uint32, mode uint32, cont ...@@ -89,7 +91,7 @@ func (fs *DefaultFileSystem) Create(name string, flags uint32, mode uint32, cont
return nil, ENOSYS return nil, ENOSYS
} }
func (fs *DefaultFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) { func (fs *DefaultFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
......
...@@ -2,6 +2,7 @@ package fuse ...@@ -2,6 +2,7 @@ package fuse
import ( import (
"log" "log"
"time"
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
...@@ -45,7 +46,7 @@ func (f *DefaultFile) Fsync(flags int) (code Status) { ...@@ -45,7 +46,7 @@ func (f *DefaultFile) Fsync(flags int) (code Status) {
return ENOSYS return ENOSYS
} }
func (f *DefaultFile) Utimens(atimeNs int64, mtimeNs int64) Status { func (f *DefaultFile) Utimens(atime *time.Time, mtime *time.Time) Status {
return ENOSYS return ENOSYS
} }
......
...@@ -2,6 +2,7 @@ package fuse ...@@ -2,6 +2,7 @@ package fuse
import ( import (
"log" "log"
"time"
) )
var _ = log.Println var _ = log.Println
...@@ -150,6 +151,6 @@ func (n *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code ...@@ -150,6 +151,6 @@ func (n *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) { func (n *DefaultFsNode) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
...@@ -63,8 +63,8 @@ func (f *MutableDataFile) GetAttr(out *Attr) Status { ...@@ -63,8 +63,8 @@ func (f *MutableDataFile) GetAttr(out *Attr) Status {
return OK return OK
} }
func (f *MutableDataFile) Utimens(atimeNs int64, mtimeNs int64) Status { func (f *MutableDataFile) Utimens(atime *time.Time, mtime *time.Time) Status {
f.Attr.SetNs(atimeNs, mtimeNs, -1) f.Attr.SetTimes(atime, mtime, nil)
return OK return OK
} }
......
...@@ -176,19 +176,26 @@ func (c *FileSystemConnector) SetAttr(out *raw.AttrOut, header *raw.InHeader, in ...@@ -176,19 +176,26 @@ func (c *FileSystemConnector) SetAttr(out *raw.AttrOut, header *raw.InHeader, in
code = node.fsInode.Truncate(f, input.Size, (*Context)(&header.Context)) code = node.fsInode.Truncate(f, input.Size, (*Context)(&header.Context))
} }
if code.Ok() && (input.Valid&(raw.FATTR_ATIME|raw.FATTR_MTIME|raw.FATTR_ATIME_NOW|raw.FATTR_MTIME_NOW) != 0) { if code.Ok() && (input.Valid&(raw.FATTR_ATIME|raw.FATTR_MTIME|raw.FATTR_ATIME_NOW|raw.FATTR_MTIME_NOW) != 0) {
now := int64(0) now := time.Now()
if input.Valid&raw.FATTR_ATIME_NOW != 0 || input.Valid&raw.FATTR_MTIME_NOW != 0 { var atime *time.Time
now = time.Now().UnixNano() var mtime *time.Time
if input.Valid&raw.FATTR_ATIME != 0 {
if input.Valid&raw.FATTR_ATIME_NOW != 0 {
atime = &now
} else {
t := time.Unix(int64(input.Atime), int64(input.Atimensec))
atime = &t
}
} }
atime := int64(input.Atime*1e9) + int64(input.Atimensec) if input.Valid&raw.FATTR_MTIME != 0 {
if input.Valid&raw.FATTR_ATIME_NOW != 0 { if input.Valid&raw.FATTR_MTIME_NOW != 0 {
atime = now mtime = &now
} } else {
t := time.Unix(int64(input.Mtime), int64(input.Mtimensec))
mtime := int64(input.Mtime*1e9) + int64(input.Mtimensec) mtime = &t
if input.Valid&raw.FATTR_MTIME_NOW != 0 { }
mtime = now
} }
code = node.fsInode.Utimens(f, atime, mtime, (*Context)(&header.Context)) code = node.fsInode.Utimens(f, atime, mtime, (*Context)(&header.Context))
......
...@@ -2,6 +2,7 @@ package fuse ...@@ -2,6 +2,7 @@ package fuse
import ( import (
"sync" "sync"
"time"
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
...@@ -118,9 +119,9 @@ func (fs *LockingFileSystem) Create(name string, flags uint32, mode uint32, cont ...@@ -118,9 +119,9 @@ func (fs *LockingFileSystem) Create(name string, flags uint32, mode uint32, cont
return fs.FileSystem.Create(name, flags, mode, context) return fs.FileSystem.Create(name, flags, mode, context)
} }
func (fs *LockingFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) { func (fs *LockingFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.FileSystem.Utimens(name, AtimeNs, CtimeNs, context) return fs.FileSystem.Utimens(name, Atime, Mtime, context)
} }
func (fs *LockingFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *LockingFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
......
...@@ -111,8 +111,16 @@ func (fs *LoopbackFileSystem) Truncate(path string, offset uint64, context *Cont ...@@ -111,8 +111,16 @@ func (fs *LoopbackFileSystem) Truncate(path string, offset uint64, context *Cont
return ToStatus(os.Truncate(fs.GetPath(path), int64(offset))) return ToStatus(os.Truncate(fs.GetPath(path), int64(offset)))
} }
func (fs *LoopbackFileSystem) Utimens(path string, AtimeNs int64, MtimeNs int64, context *Context) (code Status) { func (fs *LoopbackFileSystem) Utimens(path string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) {
return ToStatus(os.Chtimes(fs.GetPath(path), time.Unix(0, AtimeNs), time.Unix(0, MtimeNs))) var a time.Time
if Atime != nil {
a = *Atime
}
var m time.Time
if Mtime != nil {
m = *Mtime
}
return ToStatus(os.Chtimes(fs.GetPath(path), a, m))
} }
func (fs *LoopbackFileSystem) Readlink(name string, context *Context) (out string, code Status) { func (fs *LoopbackFileSystem) Readlink(name string, context *Context) (out string, code Status) {
......
...@@ -34,8 +34,8 @@ func (fs *MemNodeFs) newNode() *memNode { ...@@ -34,8 +34,8 @@ func (fs *MemNodeFs) newNode() *memNode {
fs: fs, fs: fs,
id: fs.nextFree, id: fs.nextFree,
} }
now := time.Now().UnixNano() now := time.Now()
n.info.SetNs(now, now, now) n.info.SetTimes(&now, &now, &now)
n.info.Mode = S_IFDIR | 0777 n.info.Mode = S_IFDIR | 0777
fs.nextFree++ fs.nextFree++
fs.mutex.Unlock() fs.mutex.Unlock()
...@@ -189,27 +189,31 @@ func (n *memNode) Truncate(file File, size uint64, context *Context) (code Statu ...@@ -189,27 +189,31 @@ func (n *memNode) Truncate(file File, size uint64, context *Context) (code Statu
code = ToStatus(err) code = ToStatus(err)
} }
if code.Ok() { if code.Ok() {
n.info.SetNs(-1, -1, time.Now().UnixNano()) now := time.Now()
n.info.SetTimes(nil, nil, &now)
// TODO - should update mtime too? // TODO - should update mtime too?
n.info.Size = size n.info.Size = size
} }
return code return code
} }
func (n *memNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) { func (n *memNode) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status) {
n.info.SetNs(int64(atime), int64(mtime), time.Now().UnixNano()) c := time.Now()
n.info.SetTimes(atime, mtime, &c)
return OK return OK
} }
func (n *memNode) Chmod(file File, perms uint32, context *Context) (code Status) { func (n *memNode) Chmod(file File, perms uint32, context *Context) (code Status) {
n.info.Mode = (n.info.Mode ^ 07777) | perms n.info.Mode = (n.info.Mode ^ 07777) | perms
n.info.SetNs(-1, -1, time.Now().UnixNano()) now := time.Now()
n.info.SetTimes(nil, nil, &now)
return OK return OK
} }
func (n *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) { func (n *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
n.info.Uid = uid n.info.Uid = uid
n.info.Gid = gid n.info.Gid = gid
n.info.SetNs(-1, -1, time.Now().UnixNano()) now := time.Now()
n.info.SetTimes(nil, nil, &now)
return OK return OK
} }
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"time"
) )
var _ = log.Println var _ = log.Println
...@@ -625,7 +626,7 @@ func (n *pathInode) Truncate(file File, size uint64, context *Context) (code Sta ...@@ -625,7 +626,7 @@ func (n *pathInode) Truncate(file File, size uint64, context *Context) (code Sta
return code return code
} }
func (n *pathInode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) { func (n *pathInode) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status) {
files := n.inode.Files(O_ANYWRITE) files := n.inode.Files(O_ANYWRITE)
for _, f := range files { for _, f := range files {
// TODO - pass context // TODO - pass context
......
...@@ -3,6 +3,7 @@ package fuse ...@@ -3,6 +3,7 @@ package fuse
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"time"
) )
// PrefixFileSystem adds a path prefix to incoming calls. // PrefixFileSystem adds a path prefix to incoming calls.
...@@ -87,8 +88,8 @@ func (fs *PrefixFileSystem) Create(name string, flags uint32, mode uint32, conte ...@@ -87,8 +88,8 @@ func (fs *PrefixFileSystem) Create(name string, flags uint32, mode uint32, conte
return fs.FileSystem.Create(fs.prefixed(name), flags, mode, context) return fs.FileSystem.Create(fs.prefixed(name), flags, mode, context)
} }
func (fs *PrefixFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) { func (fs *PrefixFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) {
return fs.FileSystem.Utimens(fs.prefixed(name), AtimeNs, CtimeNs, context) return fs.FileSystem.Utimens(fs.prefixed(name), Atime, Mtime, context)
} }
func (fs *PrefixFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *PrefixFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
......
...@@ -281,8 +281,9 @@ func (fs *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co ...@@ -281,8 +281,9 @@ func (fs *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co
code = writable.Chmod(name, srcResult.attr.Mode&07777|0200, context) code = writable.Chmod(name, srcResult.attr.Mode&07777|0200, context)
} }
if code.Ok() { if code.Ok() {
code = writable.Utimens(name, srcResult.attr.Atimens(), aTime := srcResult.attr.AccessTime()
srcResult.attr.Mtimens(), context) mTime := srcResult.attr.ModTime()
code = writable.Utimens(name, &aTime, &mTime, context)
} }
files := fs.nodeFs.AllFiles(name, 0) files := fs.nodeFs.AllFiles(name, 0)
...@@ -478,7 +479,7 @@ func (fs *UnionFs) Truncate(path string, size uint64, context *fuse.Context) (co ...@@ -478,7 +479,7 @@ func (fs *UnionFs) Truncate(path string, size uint64, context *fuse.Context) (co
return code return code
} }
func (fs *UnionFs) Utimens(name string, atime int64, mtime int64, context *fuse.Context) (code fuse.Status) { func (fs *UnionFs) Utimens(name string, atime *time.Time, mtime *time.Time, context *fuse.Context) (code fuse.Status) {
name = stripSlash(name) name = stripSlash(name)
r := fs.getBranch(name) r := fs.getBranch(name)
...@@ -491,7 +492,8 @@ func (fs *UnionFs) Utimens(name string, atime int64, mtime int64, context *fuse. ...@@ -491,7 +492,8 @@ func (fs *UnionFs) Utimens(name string, atime int64, mtime int64, context *fuse.
code = fs.fileSystems[0].Utimens(name, atime, mtime, context) code = fs.fileSystems[0].Utimens(name, atime, mtime, context)
} }
if code.Ok() { if code.Ok() {
r.attr.SetNs(atime, mtime, time.Now().UnixNano()) now := time.Now()
r.attr.SetTimes(atime, mtime, &now)
fs.branchCache.Set(name, r) fs.branchCache.Set(name, r)
} }
return code return code
...@@ -640,7 +642,9 @@ func (fs *UnionFs) promoteDirsTo(filename string) fuse.Status { ...@@ -640,7 +642,9 @@ func (fs *UnionFs) promoteDirsTo(filename string) fuse.Status {
return fuse.EPERM return fuse.EPERM
} }
fs.fileSystems[0].Utimens(d, r.attr.Atimens(), r.attr.Mtimens(), nil) aTime := r.attr.AccessTime()
mTime := r.attr.ModTime()
fs.fileSystems[0].Utimens(d, &aTime, &mTime, nil)
r.branch = 0 r.branch = 0
fs.branchCache.Set(d, r) fs.branchCache.Set(d, r)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment