"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
union: enable passing of options to upstreams and policies #6071
Nick Craig-Wood1d2fe0d8564b
diff --git a/backend/union/common/options.go b/backend/union/common/options.gonew file mode 100644index 000000000..cc275cc37--- /dev/null+++ b/backend/union/common/options.go@@ -0,0 +1,16 @@+// Package common defines code common to the union and the policies+//+// These need to be defined in a separate package to avoid import loops+package common++import "github.com/rclone/rclone/fs"++// Options defines the configuration for this backend+type Options struct {+ Upstreams fs.SpaceSepList `config:"upstreams"`+ Remotes fs.SpaceSepList `config:"remotes"` // Deprecated+ ActionPolicy string `config:"action_policy"`+ CreatePolicy string `config:"create_policy"`+ SearchPolicy string `config:"search_policy"`+ CacheTime int `config:"cache_time"`+}diff --git a/backend/union/union.go b/backend/union/union.goindex ed17cd020..dc4e2c589 100644--- a/backend/union/union.go+++ b/backend/union/union.go@@ -13,6 +13,7 @@ import ("sync""time"+ "github.com/rclone/rclone/backend/union/common""github.com/rclone/rclone/backend/union/policy""github.com/rclone/rclone/backend/union/upstream""github.com/rclone/rclone/fs"@@ -54,21 +55,11 @@ func init() {fs.Register(fsi)}-// Options defines the configuration for this backend-type Options struct {- Upstreams fs.SpaceSepList `config:"upstreams"`- Remotes fs.SpaceSepList `config:"remotes"` // Deprecated- ActionPolicy string `config:"action_policy"`- CreatePolicy string `config:"create_policy"`- SearchPolicy string `config:"search_policy"`- CacheTime int `config:"cache_time"`-}-// Fs represents a union of upstreamstype Fs struct {name string // name of this remotefeatures *fs.Features // optional features- opt Options // options for this Fs+ opt common.Options // options for this Fsroot string // the path we are working onupstreams []*upstream.Fs // slice of upstreamshashSet hash.Set // intersection of hash types@@ -808,7 +799,7 @@ func (f *Fs) Shutdown(ctx context.Context) error {// The returned Fs is the actual Fs, referenced by remote in the configfunc NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, error) {// Parse config into Options struct- opt := new(Options)+ opt := new(common.Options)err := configstruct.Set(m, opt)if err != nil {return nil, err@@ -836,7 +827,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, eerrs := Errors(make([]error, len(opt.Upstreams)))multithread(len(opt.Upstreams), func(i int) {u := opt.Upstreams[i]- upstreams[i], errs[i] = upstream.New(ctx, u, root, time.Duration(opt.CacheTime)*time.Second)+ upstreams[i], errs[i] = upstream.New(ctx, u, root, opt)})var usedUpstreams []*upstream.Fsvar fserr errordiff --git a/backend/union/upstream/upstream.go b/backend/union/upstream/upstream.goindex 86575c512..41f30f400 100644--- a/backend/union/upstream/upstream.go+++ b/backend/union/upstream/upstream.go@@ -11,6 +11,7 @@ import ("sync/atomic""time"+ "github.com/rclone/rclone/backend/union/common""github.com/rclone/rclone/fs""github.com/rclone/rclone/fs/cache""github.com/rclone/rclone/fs/fspath"@@ -26,6 +27,7 @@ type Fs struct {fs.FsRootFs fs.FsRootPath string+ Opt *common.Optionswritable boolcreatable boolusage *fs.Usage // Cache the usage@@ -61,17 +63,18 @@ type Entry interface {// New creates a new Fs based on the// string formatted `type:root_path(:ro/:nc)`-func New(ctx context.Context, remote, root string, cacheTime time.Duration) (*Fs, error) {+func New(ctx context.Context, remote, root string, opt *common.Options) (*Fs, error) {configName, fsPath, err := fspath.SplitFs(remote)if err != nil {return nil, err}f := &Fs{RootPath: strings.TrimRight(root, "/"),+ Opt: opt,writable: true,creatable: true,cacheExpiry: time.Now().Unix(),- cacheTime: cacheTime,+ cacheTime: time.Duration(opt.CacheTime) * time.Second,usage: &fs.Usage{},}if strings.HasSuffix(fsPath, ":ro") {