mountlib: make more useful as a general purpose file system adaptor

This commit is contained in:
Nick Craig-Wood 2017-10-24 21:06:06 +01:00
parent 014aa3d157
commit 54950d3423
4 changed files with 41 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import "fmt"
// Error describes low level errors in a cross platform way
type Error byte
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go, cmd/serve/webdav/webdav.go
// Low level errors
const (

View File

@ -9,6 +9,7 @@ import (
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// Options set by command line flags
@ -170,14 +171,8 @@ like this:
// Add flags
flags := commandDefintion.Flags()
flags.BoolVarP(&NoModTime, "no-modtime", "", NoModTime, "Don't read/write the modification time (can speed things up).")
flags.BoolVarP(&NoChecksum, "no-checksum", "", NoChecksum, "Don't compare checksums on up/download.")
flags.BoolVarP(&DebugFUSE, "debug-fuse", "", DebugFUSE, "Debug the FUSE internals - needs -v.")
flags.BoolVarP(&NoSeek, "no-seek", "", NoSeek, "Don't allow seeking in files.")
flags.DurationVarP(&DirCacheTime, "dir-cache-time", "", DirCacheTime, "Time to cache directory entries for.")
flags.DurationVarP(&PollInterval, "poll-interval", "", PollInterval, "Time to wait between polling for changes. Must be smaller than dir-cache-time. Only on supported remotes. Set to 0 to disable.")
// mount options
flags.BoolVarP(&ReadOnly, "read-only", "", ReadOnly, "Mount read-only.")
flags.BoolVarP(&AllowNonEmpty, "allow-non-empty", "", AllowNonEmpty, "Allow mounting over a non-empty directory.")
flags.BoolVarP(&AllowRoot, "allow-root", "", AllowRoot, "Allow access to root user.")
flags.BoolVarP(&AllowOther, "allow-other", "", AllowOther, "Allow access to other users.")
@ -188,6 +183,19 @@ like this:
ExtraFlags = flags.StringArrayP("fuse-flag", "", []string{}, "Flags or arguments to be passed direct to libfuse/WinFsp. Repeat if required.")
//flags.BoolVarP(&foreground, "foreground", "", foreground, "Do not detach.")
platformFlags(flags)
// Add in the generic flags
AddFlags(flags)
return commandDefintion
}
// AddFlags adds the non filing system specific flags to the command
func AddFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&NoModTime, "no-modtime", "", NoModTime, "Don't read/write the modification time (can speed things up).")
flags.BoolVarP(&NoChecksum, "no-checksum", "", NoChecksum, "Don't compare checksums on up/download.")
flags.BoolVarP(&NoSeek, "no-seek", "", NoSeek, "Don't allow seeking in files.")
flags.DurationVarP(&DirCacheTime, "dir-cache-time", "", DirCacheTime, "Time to cache directory entries for.")
flags.DurationVarP(&PollInterval, "poll-interval", "", PollInterval, "Time to wait between polling for changes. Must be smaller than dir-cache-time. Only on supported remotes. Set to 0 to disable.")
flags.BoolVarP(&ReadOnly, "read-only", "", ReadOnly, "Mount read-only.")
platformFlags(flags)
}

View File

@ -271,3 +271,18 @@ func (fh *ReadFileHandle) Release() error {
}
return err
}
// Size returns the size of the underlying file
func (fh *ReadFileHandle) Size() int64 {
return fh.o.Size()
}
// Close closes the file calling Flush then Release
func (fh *ReadFileHandle) Close() error {
err := fh.Flush()
err2 := fh.Release()
if err != nil {
return err
}
return err2
}

View File

@ -165,3 +165,13 @@ func (fh *WriteFileHandle) Release() error {
}
return err
}
// Close closes the file calling Flush then Release
func (fh *WriteFileHandle) Close() error {
err := fh.Flush()
err2 := fh.Release()
if err != nil {
return err
}
return err2
}