From ab18be237833e81fce17bda9232713626e0761c4 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 6 Mar 2015 05:23:44 +1100 Subject: [PATCH] Refactored inode time tracking. --- samples/memfs/fs.go | 15 +++++---------- samples/memfs/inode.go | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 312963e..b65bc26 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -74,7 +74,7 @@ func NewMemFS( Mode: 0700 | os.ModeDir, } - fs.inodes[fuse.RootInodeID] = newInode(rootAttrs) + fs.inodes[fuse.RootInodeID] = newInode(clock, rootAttrs) // Set up invariant checking. fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants) @@ -163,7 +163,7 @@ func (fs *memFS) getInodeForReadingOrDie(id fuse.InodeID) (inode *inode) { func (fs *memFS) allocateInode( attrs fuse.InodeAttributes) (id fuse.InodeID, inode *inode) { // Create and lock the inode. - inode = newInode(attrs) + inode = newInode(fs.clock, attrs) inode.mu.Lock() // Re-use a free ID if possible. Otherwise mint a new one. @@ -281,15 +281,10 @@ func (fs *memFS) MkDir( // Set up attributes from the child, using the credentials of the calling // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). - now := fs.clock.Now() childAttrs := fuse.InodeAttributes{ - Mode: req.Mode, - Atime: now, - Mtime: now, - Ctime: now, - Crtime: now, - Uid: req.Header.Uid, - Gid: req.Header.Gid, + Mode: req.Mode, + Uid: req.Header.Uid, + Gid: req.Header.Gid, } // Allocate a child. diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index 3ef46b6..477182c 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -22,6 +22,7 @@ import ( "github.com/jacobsa/fuse" "github.com/jacobsa/fuse/fuseutil" "github.com/jacobsa/gcloud/syncutil" + "github.com/jacobsa/gcsfuse/timeutil" ) // Common attributes for files and directories. @@ -30,6 +31,12 @@ import ( // been unlinked, including creating a new file. Make sure we don't screw up // and reuse an inode ID while it is still in use. type inode struct { + ///////////////////////// + // Dependencies + ///////////////////////// + + clock timeutil.Clock + ///////////////////////// // Constant data ///////////////////////// @@ -84,9 +91,22 @@ type inode struct { // Helpers //////////////////////////////////////////////////////////////////////// +// Create a new inode with the supplied attributes, which need not contain +// time-related information (the inode object will take care of that). // Initially the link count is one. -func newInode(attrs fuse.InodeAttributes) (in *inode) { +func newInode( + clock timeutil.Clock, + attrs fuse.InodeAttributes) (in *inode) { + // Update time info. + now := clock.Now() + attrs.Atime = now + attrs.Mtime = now + attrs.Ctime = now + attrs.Crtime = now + + // Create the object. in = &inode{ + clock: clock, linkCount: 1, dir: (attrs.Mode&os.ModeDir != 0), attributes: attrs,