diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go index 44ac47cc4..3269effa0 100644 --- a/cmd/cmount/fs.go +++ b/cmd/cmount/fs.go @@ -51,6 +51,7 @@ func NewFS(f fs.Fs) *FS { if pollInterval > 0 { fsys.FS.PollChanges(pollInterval) } + fsys.FS.SetDirCacheTime(dirCacheTime) return fsys } diff --git a/cmd/mount/fs.go b/cmd/mount/fs.go index a5f12cd71..385bc1fa1 100644 --- a/cmd/mount/fs.go +++ b/cmd/mount/fs.go @@ -42,6 +42,7 @@ func NewFS(f fs.Fs) *FS { if pollInterval > 0 { fsys.FS.PollChanges(pollInterval) } + fsys.FS.SetDirCacheTime(dirCacheTime) return fsys } diff --git a/cmd/mountlib/dir.go b/cmd/mountlib/dir.go index d8ea6ae74..e51401232 100644 --- a/cmd/mountlib/dir.go +++ b/cmd/mountlib/dir.go @@ -10,8 +10,6 @@ import ( "github.com/pkg/errors" ) -var dirCacheTime = 60 * time.Second // FIXME needs to be settable - // DirEntry describes the contents of a directory entry // // It can be a file or a directory @@ -152,7 +150,7 @@ func (d *Dir) readDir() error { // fs.Debugf(d.path, "Reading directory") } else { age := when.Sub(d.read) - if age < dirCacheTime { + if age < d.fsys.dirCacheTime { return nil } fs.Debugf(d.path, "Re-reading directory (%v old)", age) diff --git a/cmd/mountlib/fs.go b/cmd/mountlib/fs.go index 2dc5361a8..3d73b671c 100644 --- a/cmd/mountlib/fs.go +++ b/cmd/mountlib/fs.go @@ -35,11 +35,12 @@ var ( // FS represents the top level filing system type FS struct { - f fs.Fs - root *Dir - noSeek bool // don't allow seeking if set - noChecksum bool // don't check checksums if set - readOnly bool // if set FS is read only + f fs.Fs + root *Dir + noSeek bool // don't allow seeking if set + noChecksum bool // don't check checksums if set + readOnly bool // if set FS is read only + dirCacheTime time.Duration // how long to consider directory listing cache valid } // NewFS creates a new filing system and root directory @@ -57,6 +58,13 @@ func NewFS(f fs.Fs) *FS { return fsys } +// SetDirCacheTime allows to set how long a directory listing is considered +// valid. Set to 0 always request a fresh version from the remote. +func (fsys *FS) SetDirCacheTime(dirCacheTime time.Duration) *FS { + fsys.dirCacheTime = dirCacheTime + return fsys +} + // PollChanges will poll the remote every pollInterval for changes if the remote // supports it. If a non-polling option is used, the given time interval can be // ignored