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