Refactored inode time tracking.
parent
62bda89ca9
commit
ab18be2378
|
@ -74,7 +74,7 @@ func NewMemFS(
|
||||||
Mode: 0700 | os.ModeDir,
|
Mode: 0700 | os.ModeDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.inodes[fuse.RootInodeID] = newInode(rootAttrs)
|
fs.inodes[fuse.RootInodeID] = newInode(clock, rootAttrs)
|
||||||
|
|
||||||
// Set up invariant checking.
|
// Set up invariant checking.
|
||||||
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
|
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
|
||||||
|
@ -163,7 +163,7 @@ func (fs *memFS) getInodeForReadingOrDie(id fuse.InodeID) (inode *inode) {
|
||||||
func (fs *memFS) allocateInode(
|
func (fs *memFS) allocateInode(
|
||||||
attrs fuse.InodeAttributes) (id fuse.InodeID, inode *inode) {
|
attrs fuse.InodeAttributes) (id fuse.InodeID, inode *inode) {
|
||||||
// Create and lock the inode.
|
// Create and lock the inode.
|
||||||
inode = newInode(attrs)
|
inode = newInode(fs.clock, attrs)
|
||||||
inode.mu.Lock()
|
inode.mu.Lock()
|
||||||
|
|
||||||
// Re-use a free ID if possible. Otherwise mint a new one.
|
// 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
|
// Set up attributes from the child, using the credentials of the calling
|
||||||
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
|
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
|
||||||
now := fs.clock.Now()
|
|
||||||
childAttrs := fuse.InodeAttributes{
|
childAttrs := fuse.InodeAttributes{
|
||||||
Mode: req.Mode,
|
Mode: req.Mode,
|
||||||
Atime: now,
|
Uid: req.Header.Uid,
|
||||||
Mtime: now,
|
Gid: req.Header.Gid,
|
||||||
Ctime: now,
|
|
||||||
Crtime: now,
|
|
||||||
Uid: req.Header.Uid,
|
|
||||||
Gid: req.Header.Gid,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a child.
|
// Allocate a child.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
"github.com/jacobsa/fuse/fuseutil"
|
"github.com/jacobsa/fuse/fuseutil"
|
||||||
"github.com/jacobsa/gcloud/syncutil"
|
"github.com/jacobsa/gcloud/syncutil"
|
||||||
|
"github.com/jacobsa/gcsfuse/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common attributes for files and directories.
|
// 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
|
// 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.
|
// and reuse an inode ID while it is still in use.
|
||||||
type inode struct {
|
type inode struct {
|
||||||
|
/////////////////////////
|
||||||
|
// Dependencies
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
|
clock timeutil.Clock
|
||||||
|
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
// Constant data
|
// Constant data
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
@ -84,9 +91,22 @@ type inode struct {
|
||||||
// Helpers
|
// 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.
|
// 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{
|
in = &inode{
|
||||||
|
clock: clock,
|
||||||
linkCount: 1,
|
linkCount: 1,
|
||||||
dir: (attrs.Mode&os.ModeDir != 0),
|
dir: (attrs.Mode&os.ModeDir != 0),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
|
|
Loading…
Reference in New Issue