mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 13:26:11 +08:00
0d066bdf46
Before this change, when the above backends created a new backend they didn't put it into the backend cache. This meant that rc commands acting on those backends did not work. This was fixed by making sure the backends use the backend cache. See: https://forum.rclone.org/t/rclone-rc-backend-command-not-working-as-expected/18834
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package alias
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fs/cache"
|
|
"github.com/rclone/rclone/fs/config/configmap"
|
|
"github.com/rclone/rclone/fs/config/configstruct"
|
|
"github.com/rclone/rclone/fs/fspath"
|
|
)
|
|
|
|
// Register with Fs
|
|
func init() {
|
|
fsi := &fs.RegInfo{
|
|
Name: "alias",
|
|
Description: "Alias for an existing remote",
|
|
NewFs: NewFs,
|
|
Options: []fs.Option{{
|
|
Name: "remote",
|
|
Help: "Remote or path to alias.\nCan be \"myremote:path/to/dir\", \"myremote:bucket\", \"myremote:\" or \"/local/path\".",
|
|
Required: true,
|
|
}},
|
|
}
|
|
fs.Register(fsi)
|
|
}
|
|
|
|
// Options defines the configuration for this backend
|
|
type Options struct {
|
|
Remote string `config:"remote"`
|
|
}
|
|
|
|
// NewFs constructs an Fs from the path.
|
|
//
|
|
// The returned Fs is the actual Fs, referenced by remote in the config
|
|
func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|
// Parse config into Options struct
|
|
opt := new(Options)
|
|
err := configstruct.Set(m, opt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if opt.Remote == "" {
|
|
return nil, errors.New("alias can't point to an empty remote - check the value of the remote setting")
|
|
}
|
|
if strings.HasPrefix(opt.Remote, name+":") {
|
|
return nil, errors.New("can't point alias remote at itself - check the value of the remote setting")
|
|
}
|
|
return cache.Get(fspath.JoinRootPath(opt.Remote, root))
|
|
}
|