vfs: Move DefaultOpt to vfs and make some methods private
This commit is contained in:
parent
7e065440fb
commit
3e0c91ba4b
4 changed files with 32 additions and 35 deletions
|
@ -34,7 +34,7 @@ func newDir(vfs *VFS, f fs.Fs, parent *Dir, fsDir fs.Directory) *Dir {
|
||||||
entry: fsDir,
|
entry: fsDir,
|
||||||
path: fsDir.Remote(),
|
path: fsDir.Remote(),
|
||||||
modTime: fsDir.ModTime(),
|
modTime: fsDir.ModTime(),
|
||||||
inode: NewInode(),
|
inode: newInode(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func newFile(d *Dir, o fs.Object, leaf string) *File {
|
||||||
d: d,
|
d: d,
|
||||||
o: o,
|
o: o,
|
||||||
leaf: leaf,
|
leaf: leaf,
|
||||||
inode: NewInode(),
|
inode: newInode(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
vfs/vfs.go
46
vfs/vfs.go
|
@ -19,6 +19,21 @@ import (
|
||||||
"github.com/ncw/rclone/fs"
|
"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)
|
// Node represents either a directory (*Dir) or a file (*File)
|
||||||
type Node interface {
|
type Node interface {
|
||||||
os.FileInfo
|
os.FileInfo
|
||||||
|
@ -83,12 +98,18 @@ type Options struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new VFS and root directory. If opt is nil, then
|
// 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 {
|
func New(f fs.Fs, opt *Options) *VFS {
|
||||||
fsDir := fs.NewDir("", time.Now())
|
fsDir := fs.NewDir("", time.Now())
|
||||||
vfs := &VFS{
|
vfs := &VFS{
|
||||||
f: f,
|
f: f,
|
||||||
Opt: *opt,
|
}
|
||||||
|
|
||||||
|
// Make a copy of the options
|
||||||
|
if opt != nil {
|
||||||
|
vfs.Opt = *opt
|
||||||
|
} else {
|
||||||
|
vfs.Opt = DefaultOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mask the permissions with the umask
|
// Mask the permissions with the umask
|
||||||
|
@ -100,18 +121,9 @@ func New(f fs.Fs, opt *Options) *VFS {
|
||||||
|
|
||||||
// Start polling if required
|
// Start polling if required
|
||||||
if vfs.Opt.PollInterval > 0 {
|
if vfs.Opt.PollInterval > 0 {
|
||||||
vfs.PollChanges(vfs.Opt.PollInterval)
|
if do := vfs.f.Features().DirChangeNotify; do != nil {
|
||||||
}
|
do(vfs.root.ForgetPath, 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)
|
|
||||||
}
|
}
|
||||||
return vfs
|
return vfs
|
||||||
}
|
}
|
||||||
|
@ -124,8 +136,8 @@ func (vfs *VFS) Root() (*Dir, error) {
|
||||||
|
|
||||||
var inodeCount uint64
|
var inodeCount uint64
|
||||||
|
|
||||||
// NewInode creates a new unique inode number
|
// newInode creates a new unique inode number
|
||||||
func NewInode() (inode uint64) {
|
func newInode() (inode uint64) {
|
||||||
return atomic.AddUint64(&inodeCount, 1)
|
return atomic.AddUint64(&inodeCount, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,28 +2,13 @@
|
||||||
package vfsflags
|
package vfsflags
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ncw/rclone/vfs"
|
"github.com/ncw/rclone/vfs"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options set by command line flags
|
// Options set by command line flags
|
||||||
var (
|
var (
|
||||||
Opt = vfs.Options{
|
Opt = vfs.DefaultOpt
|
||||||
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),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddFlags adds the non filing system specific flags to the command
|
// AddFlags adds the non filing system specific flags to the command
|
||||||
|
|
Loading…
Reference in a new issue