mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
mountlib: add rc command mount/types and rename mountOption to mountType
This commit is contained in:
parent
5f168b3b96
commit
1319d7333c
@ -3,6 +3,7 @@ package mountlib
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/fs"
|
||||
@ -16,6 +17,18 @@ var (
|
||||
unmountFns map[string]UnmountFn
|
||||
)
|
||||
|
||||
// AddRc adds mount and unmount functionality to rc
|
||||
func AddRc(mountUtilName string, mountFunction MountFn) {
|
||||
if mountFns == nil {
|
||||
mountFns = make(map[string]MountFn)
|
||||
}
|
||||
if unmountFns == nil {
|
||||
unmountFns = make(map[string]UnmountFn)
|
||||
}
|
||||
// rcMount allows the mount command to be run from rc
|
||||
mountFns[mountUtilName] = mountFunction
|
||||
}
|
||||
|
||||
func init() {
|
||||
rc.Add(rc.Call{
|
||||
Path: "mount/mount",
|
||||
@ -25,21 +38,60 @@ func init() {
|
||||
Help: `rclone allows Linux, FreeBSD, macOS and Windows to mount any of
|
||||
Rclone's cloud storage systems as a file system with FUSE.
|
||||
|
||||
If no mountOption is provided, the priority is given as follows: 1. mount 2.cmount 3.mount2
|
||||
If no mountType is provided, the priority is given as follows: 1. mount 2.cmount 3.mount2
|
||||
|
||||
This takes the following parameters
|
||||
|
||||
- fs - a remote path to be mounted (required)
|
||||
- mountPoint: valid path on the local machine (required)
|
||||
- mountOption: One of the values (mount, cmount, mount2) specifies the mount implementation to use
|
||||
- mountType: One of the values (mount, cmount, mount2) specifies the mount implementation to use
|
||||
|
||||
Eg
|
||||
|
||||
rclone rc mount/mount fs=mydrive: mountPoint=/home/<user>/mountPoint
|
||||
rclone rc mount/mount fs=mydrive: mountPoint=/home/<user>/mountPoint mountOption=mount
|
||||
rclone rc mount/mount fs=mydrive: mountPoint=/home/<user>/mountPoint mountType=mount
|
||||
`,
|
||||
})
|
||||
}
|
||||
|
||||
// rcMount allows the mount command to be run from rc
|
||||
func mountRc(_ context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
mountPoint, err := in.GetString("mountPoint")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mountType, err := in.GetString("mountType")
|
||||
|
||||
if err != nil || mountType == "" {
|
||||
if mountFns["mount"] != nil {
|
||||
mountType = "mount"
|
||||
} else if mountFns["cmount"] != nil {
|
||||
mountType = "cmount"
|
||||
} else if mountFns["mount2"] != nil {
|
||||
mountType = "mount2"
|
||||
}
|
||||
}
|
||||
|
||||
// Get Fs.fs to be mounted from fs parameter in the params
|
||||
fdst, err := rc.GetFs(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if mountFns[mountType] != nil {
|
||||
_, _, unmountFns[mountPoint], err = mountFns[mountType](fdst, mountPoint)
|
||||
if err != nil {
|
||||
log.Printf("mount FAILED: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
fs.Debugf(nil, "Mount for %s created at %s using %s", fdst.String(), mountPoint, mountType)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.New("Mount Option specified is not registered, or is invalid")
|
||||
}
|
||||
|
||||
func init() {
|
||||
rc.Add(rc.Call{
|
||||
Path: "mount/unmount",
|
||||
AuthRequired: true,
|
||||
@ -59,19 +111,6 @@ Eg
|
||||
rclone rc mount/unmount mountPoint=/home/<user>/mountPoint
|
||||
`,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// AddRc adds mount and unmount functionality to rc
|
||||
func AddRc(mountUtilName string, mountFunction MountFn) {
|
||||
if mountFns == nil {
|
||||
mountFns = make(map[string]MountFn)
|
||||
}
|
||||
if unmountFns == nil {
|
||||
unmountFns = make(map[string]UnmountFn)
|
||||
}
|
||||
// rcMount allows the mount command to be run from rc
|
||||
mountFns[mountUtilName] = mountFunction
|
||||
}
|
||||
|
||||
// rcMount allows the umount command to be run from rc
|
||||
@ -94,39 +133,36 @@ func unMountRc(_ context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// rcMount allows the mount command to be run from rc
|
||||
func mountRc(_ context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
mountPoint, err := in.GetString("mountPoint")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func init() {
|
||||
rc.Add(rc.Call{
|
||||
Path: "mount/types",
|
||||
AuthRequired: true,
|
||||
Fn: mountTypesRc,
|
||||
Title: "Show all possible mount types",
|
||||
Help: `This shows all possible mount types and returns them as a list.
|
||||
|
||||
mountOption, err := in.GetString("mountOption")
|
||||
This takes no parameters and returns
|
||||
|
||||
if err != nil || mountOption == "" {
|
||||
if mountFns["mount"] != nil {
|
||||
mountOption = "mount"
|
||||
} else if mountFns["cmount"] != nil {
|
||||
mountOption = "cmount"
|
||||
} else if mountFns["mount2"] != nil {
|
||||
mountOption = "mount2"
|
||||
}
|
||||
}
|
||||
- mountTypes: list of mount types
|
||||
|
||||
// Get Fs.fs to be mounted from fs parameter in the params
|
||||
fdst, err := rc.GetFs(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
The mount types are strings like "mount", "mount2", "cmount" and can
|
||||
be passed to mount/mount as the mountType parameter.
|
||||
|
||||
if mountFns[mountOption] != nil {
|
||||
_, _, unmountFns[mountPoint], err = mountFns[mountOption](fdst, mountPoint)
|
||||
if err != nil {
|
||||
log.Printf("mount FAILED: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
fs.Debugf(nil, "Mount for %s created at %s using %s", fdst.String(), mountPoint, mountOption)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.New("Mount Option specified is not registered, or is invalid")
|
||||
Eg
|
||||
|
||||
rclone rc mount/types
|
||||
`,
|
||||
})
|
||||
}
|
||||
|
||||
// mountTypesRc returns a list of available mount types.
|
||||
func mountTypesRc(_ context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
var mountTypes = []string{}
|
||||
for mountType := range mountFns {
|
||||
mountTypes = append(mountTypes, mountType)
|
||||
}
|
||||
sort.Strings(mountTypes)
|
||||
return rc.Params{
|
||||
"mountTypes": mountTypes,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user