From 3e0c91ba4b93fe2574e626c8dc06373dd75eda7f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 29 Oct 2017 17:37:54 +0000 Subject: [PATCH] vfs: Move DefaultOpt to vfs and make some methods private --- vfs/dir.go | 2 +- vfs/file.go | 2 +- vfs/vfs.go | 46 +++++++++++++++++++++++++--------------- vfs/vfsflags/vfsflags.go | 17 +-------------- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/vfs/dir.go b/vfs/dir.go index 950180650..7ba6a96a3 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -34,7 +34,7 @@ func newDir(vfs *VFS, f fs.Fs, parent *Dir, fsDir fs.Directory) *Dir { entry: fsDir, path: fsDir.Remote(), modTime: fsDir.ModTime(), - inode: NewInode(), + inode: newInode(), } } diff --git a/vfs/file.go b/vfs/file.go index d0d2133eb..0dc9e711c 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -29,7 +29,7 @@ func newFile(d *Dir, o fs.Object, leaf string) *File { d: d, o: o, leaf: leaf, - inode: NewInode(), + inode: newInode(), } } diff --git a/vfs/vfs.go b/vfs/vfs.go index 7818761aa..c5d2828a2 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -19,6 +19,21 @@ import ( "github.com/ncw/rclone/fs" ) +// DefaultOpt is the default values uses for Opt +var DefaultOpt = Options{ + NoModTime: false, + NoChecksum: false, + NoSeek: false, + DirCacheTime: 5 * 60 * time.Second, + PollInterval: time.Minute, + ReadOnly: false, + Umask: 0, + UID: ^uint32(0), // these values instruct WinFSP-FUSE to use the current user + GID: ^uint32(0), // overriden for non windows in mount_unix.go + DirPerms: os.FileMode(0777), + FilePerms: os.FileMode(0666), +} + // Node represents either a directory (*Dir) or a file (*File) type Node interface { os.FileInfo @@ -83,12 +98,18 @@ type Options struct { } // New creates a new VFS and root directory. If opt is nil, then -// defaults will be used. +// DefaultOpt will be used func New(f fs.Fs, opt *Options) *VFS { fsDir := fs.NewDir("", time.Now()) vfs := &VFS{ - f: f, - Opt: *opt, + f: f, + } + + // Make a copy of the options + if opt != nil { + vfs.Opt = *opt + } else { + vfs.Opt = DefaultOpt } // Mask the permissions with the umask @@ -100,18 +121,9 @@ func New(f fs.Fs, opt *Options) *VFS { // Start polling if required if vfs.Opt.PollInterval > 0 { - vfs.PollChanges(vfs.Opt.PollInterval) - } - return vfs -} - -// 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 -func (vfs *VFS) PollChanges(pollInterval time.Duration) *VFS { - doDirChangeNotify := vfs.f.Features().DirChangeNotify - if doDirChangeNotify != nil { - doDirChangeNotify(vfs.root.ForgetPath, pollInterval) + if do := vfs.f.Features().DirChangeNotify; do != nil { + do(vfs.root.ForgetPath, vfs.Opt.PollInterval) + } } return vfs } @@ -124,8 +136,8 @@ func (vfs *VFS) Root() (*Dir, error) { var inodeCount uint64 -// NewInode creates a new unique inode number -func NewInode() (inode uint64) { +// newInode creates a new unique inode number +func newInode() (inode uint64) { return atomic.AddUint64(&inodeCount, 1) } diff --git a/vfs/vfsflags/vfsflags.go b/vfs/vfsflags/vfsflags.go index 053213079..265587cb3 100644 --- a/vfs/vfsflags/vfsflags.go +++ b/vfs/vfsflags/vfsflags.go @@ -2,28 +2,13 @@ package vfsflags import ( - "os" - "time" - "github.com/ncw/rclone/vfs" "github.com/spf13/pflag" ) // Options set by command line flags var ( - Opt = vfs.Options{ - NoModTime: false, - NoChecksum: false, - NoSeek: false, - DirCacheTime: 5 * 60 * time.Second, - PollInterval: time.Minute, - ReadOnly: false, - Umask: 0, - UID: ^uint32(0), // these values instruct WinFSP-FUSE to use the current user - GID: ^uint32(0), // overriden for non windows in mount_unix.go - DirPerms: os.FileMode(0777), - FilePerms: os.FileMode(0666), - } + Opt = vfs.DefaultOpt ) // AddFlags adds the non filing system specific flags to the command