mount: report the modification times for directories from the remote #940 #950

This stops the modification times for directories just being the
current time and reads them from the remote instead.  This doesn't
take any extra transactions.
This commit is contained in:
Nick Craig-Wood 2016-12-14 15:26:04 +00:00
parent 8083804575
commit 13b705e227
2 changed files with 23 additions and 11 deletions

View file

@ -27,17 +27,19 @@ type DirEntry struct {
// Dir represents a directory entry // Dir represents a directory entry
type Dir struct { type Dir struct {
f fs.Fs f fs.Fs
path string path string
mu sync.RWMutex // protects the following modTime time.Time
read time.Time // time directory entry last read mu sync.RWMutex // protects the following
items map[string]*DirEntry read time.Time // time directory entry last read
items map[string]*DirEntry
} }
func newDir(f fs.Fs, path string) *Dir { func newDir(f fs.Fs, fsDir *fs.Dir) *Dir {
return &Dir{ return &Dir{
f: f, f: f,
path: path, path: fsDir.Name,
modTime: fsDir.When,
} }
} }
@ -154,6 +156,10 @@ func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) error {
a.Gid = gid a.Gid = gid
a.Uid = uid a.Uid = uid
a.Mode = os.ModeDir | dirPerms a.Mode = os.ModeDir | dirPerms
a.Atime = d.modTime
a.Mtime = d.modTime
a.Ctime = d.modTime
a.Crtime = d.modTime
// FIXME include Valid so get some caching? Also mtime // FIXME include Valid so get some caching? Also mtime
return nil return nil
} }
@ -172,7 +178,7 @@ func (d *Dir) lookupNode(leaf string) (item *DirEntry, err error) {
case fs.Object: case fs.Object:
node, err = newFile(d, x), nil node, err = newFile(d, x), nil
case *fs.Dir: case *fs.Dir:
node, err = newDir(d.f, x.Remote()), nil node, err = newDir(d.f, x), nil
default: default:
err = errors.Errorf("unknown type %T", item) err = errors.Errorf("unknown type %T", item)
} }
@ -275,7 +281,7 @@ func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fusefs.Node, e
Name: path, Name: path,
When: time.Now(), When: time.Now(),
} }
dir := newDir(d.f, path) dir := newDir(d.f, fsDir)
d.addObject(fsDir, dir) d.addObject(fsDir, dir)
fs.Debug(path, "Dir.Mkdir OK") fs.Debug(path, "Dir.Mkdir OK")
return dir, nil return dir, nil

View file

@ -5,6 +5,8 @@
package mount package mount
import ( import (
"time"
"bazil.org/fuse" "bazil.org/fuse"
fusefs "bazil.org/fuse/fs" fusefs "bazil.org/fuse/fs"
"github.com/ncw/rclone/fs" "github.com/ncw/rclone/fs"
@ -22,7 +24,11 @@ var _ fusefs.FS = (*FS)(nil)
// Root returns the root node // Root returns the root node
func (f *FS) Root() (fusefs.Node, error) { func (f *FS) Root() (fusefs.Node, error) {
fs.Debug(f.f, "Root()") fs.Debug(f.f, "Root()")
return newDir(f.f, ""), nil fsDir := &fs.Dir{
Name: "",
When: time.Now(),
}
return newDir(f.f, fsDir), nil
} }
// mountOptions configures the options from the command line flags // mountOptions configures the options from the command line flags