diff --git a/cmd/mountlib/errors.go b/cmd/mountlib/errors.go index 6c00e78cc..1cd20a19f 100644 --- a/cmd/mountlib/errors.go +++ b/cmd/mountlib/errors.go @@ -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 ( diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go index a78e88916..a57c482d1 100644 --- a/cmd/mountlib/mount.go +++ b/cmd/mountlib/mount.go @@ -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) +} diff --git a/cmd/mountlib/read.go b/cmd/mountlib/read.go index 6019b1b18..fd7cf5408 100644 --- a/cmd/mountlib/read.go +++ b/cmd/mountlib/read.go @@ -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 +} diff --git a/cmd/mountlib/write.go b/cmd/mountlib/write.go index a273c06ff..f17b3c6ca 100644 --- a/cmd/mountlib/write.go +++ b/cmd/mountlib/write.go @@ -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 +}