2019-05-23 19:26:16 +08:00
|
|
|
// Utilities for accessing the Fs cache
|
2018-10-26 21:48:22 +08:00
|
|
|
|
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/cache"
|
2018-10-26 21:48:22 +08:00
|
|
|
)
|
|
|
|
|
2020-05-20 18:39:20 +08:00
|
|
|
// GetFsNamed gets an fs.Fs named fsName either from the cache or creates it afresh
|
2018-10-28 01:29:20 +08:00
|
|
|
func GetFsNamed(in Params, fsName string) (f fs.Fs, err error) {
|
|
|
|
fsString, err := in.GetString(fsName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-05-23 19:26:16 +08:00
|
|
|
return cache.Get(fsString)
|
2018-10-28 01:29:20 +08:00
|
|
|
}
|
|
|
|
|
2020-05-20 18:39:20 +08:00
|
|
|
// GetFs gets an fs.Fs named "fs" either from the cache or creates it afresh
|
2018-10-26 21:48:22 +08:00
|
|
|
func GetFs(in Params) (f fs.Fs, err error) {
|
|
|
|
return GetFsNamed(in, "fs")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFsAndRemoteNamed gets the fsName parameter from in, makes a
|
|
|
|
// remote or fetches it from the cache then gets the remoteName
|
|
|
|
// parameter from in too.
|
|
|
|
func GetFsAndRemoteNamed(in Params, fsName, remoteName string) (f fs.Fs, remote string, err error) {
|
|
|
|
remote, err = in.GetString(remoteName)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f, err = GetFsNamed(in, fsName)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFsAndRemote gets the `fs` parameter from in, makes a remote or
|
|
|
|
// fetches it from the cache then gets the `remote` parameter from in
|
|
|
|
// too.
|
|
|
|
func GetFsAndRemote(in Params) (f fs.Fs, remote string, err error) {
|
|
|
|
return GetFsAndRemoteNamed(in, "fs", "remote")
|
|
|
|
}
|