mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 23:22:08 +01:00
vfs: Move DefaultOpt to vfs and make some methods private
This commit is contained in:
parent
7e065440fb
commit
3e0c91ba4b
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ func newFile(d *Dir, o fs.Object, leaf string) *File {
|
||||
d: d,
|
||||
o: o,
|
||||
leaf: leaf,
|
||||
inode: NewInode(),
|
||||
inode: newInode(),
|
||||
}
|
||||
}
|
||||
|
||||
|
46
vfs/vfs.go
46
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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user