mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
58c99427b3
Some environment variables didn’t behave like their corresponding command line flags. The affected flags were --stats, --log-level, --separator, --multi-tread-streams, --rc-addr, --rc-user and --rc-pass. Example: RCLONE_STATS='10s' rclone check remote: remote: --progress # Expected: rclone check remote: remote: --progress –-stats=10s # Actual: rclone check remote: remote: --progress Remote specific options set by environment variables was overruled by less specific backend options set by environment variables. Example: RCLONE_DRIVE_USE_TRASH='false' RCLONE_CONFIG_MYDRIVE_USE_TRASH='true' rclone deletefile myDrive:my-test-file # Expected: my-test-file is recoverable in the trash folder # Actual: my-test-file is permanently deleted (not recoverable) Backend specific options set by environment variables was overruled by general backend options set by environment variables. Example: RCLONE_SKIP_LINKS='true' RCLONE_LOCAL_SKIP_LINKS='false' rclone lsd local: # Expected result: Warnings when symlinks are skipped # Actual result: No warnings when symlinks are skipped # That is RCLONE_SKIP_LINKS takes precedence The above issues have been fixed. The debug logging (-vv) has been enhanced to show when flags are set by environment variables. The documentation has been enhanced with details on the precedence of configuration options. See pull request #5341 for more information.
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
// Define the registry
|
|
|
|
package rc
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// Func defines a type for a remote control function
|
|
type Func func(ctx context.Context, in Params) (out Params, err error)
|
|
|
|
// Call defines info about a remote control function and is used in
|
|
// the Add function to create new entry points.
|
|
type Call struct {
|
|
Path string // path to activate this RC
|
|
Fn Func `json:"-"` // function to call
|
|
Title string // help for the function
|
|
AuthRequired bool // if set then this call requires authorisation to be set
|
|
Help string // multi-line markdown formatted help
|
|
NeedsRequest bool // if set then this call will be passed the original request object as _request
|
|
NeedsResponse bool // if set then this call will be passed the original response object as _response
|
|
}
|
|
|
|
// Registry holds the list of all the registered remote control functions
|
|
type Registry struct {
|
|
mu sync.RWMutex
|
|
call map[string]*Call
|
|
}
|
|
|
|
// NewRegistry makes a new registry for remote control functions
|
|
func NewRegistry() *Registry {
|
|
return &Registry{
|
|
call: make(map[string]*Call),
|
|
}
|
|
}
|
|
|
|
// Add a call to the registry
|
|
func (r *Registry) Add(call Call) {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
call.Path = strings.Trim(call.Path, "/")
|
|
call.Help = strings.TrimSpace(call.Help)
|
|
// fs.Debugf(nil, "Adding path %q to remote control registry", call.Path) // disabled to make initialization less verbose
|
|
r.call[call.Path] = &call
|
|
}
|
|
|
|
// Get a Call from a path or nil
|
|
func (r *Registry) Get(path string) *Call {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
return r.call[path]
|
|
}
|
|
|
|
// List of all calls in alphabetical order
|
|
func (r *Registry) List() (out []*Call) {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
var keys []string
|
|
for key := range r.call {
|
|
keys = append(keys, key)
|
|
}
|
|
sort.Strings(keys)
|
|
for _, key := range keys {
|
|
out = append(out, r.call[key])
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Calls is the global registry of Call objects
|
|
var Calls = NewRegistry()
|
|
|
|
// Add a function to the global registry
|
|
func Add(call Call) {
|
|
Calls.Add(call)
|
|
}
|