mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
fs: Add --disable flag to disable optional features - fixes #1551
Eg to disable server side copy use `--disable copy`, to see a list of what you can disable, `--disable help`.
This commit is contained in:
46
fs/fs.go
46
fs/fs.go
@@ -8,8 +8,10 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -347,6 +349,46 @@ type Features struct {
|
||||
ListR ListRFn
|
||||
}
|
||||
|
||||
// Disable nil's out the named feature. If it isn't found then it
|
||||
// will log a message.
|
||||
func (ft *Features) Disable(name string) *Features {
|
||||
v := reflect.ValueOf(ft).Elem()
|
||||
vType := v.Type()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
vName := vType.Field(i).Name
|
||||
field := v.Field(i)
|
||||
if strings.EqualFold(name, vName) {
|
||||
if !field.CanSet() {
|
||||
Errorf(nil, "Can't set Feature %q", name)
|
||||
} else {
|
||||
zero := reflect.Zero(field.Type())
|
||||
field.Set(zero)
|
||||
Debugf(nil, "Reset feature %q", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ft
|
||||
}
|
||||
|
||||
// List returns a slice of all the possible feature names
|
||||
func (ft *Features) List() (out []string) {
|
||||
v := reflect.ValueOf(ft).Elem()
|
||||
vType := v.Type()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
out = append(out, vType.Field(i).Name)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// DisableList nil's out the comma separated list of named features.
|
||||
// If it isn't found then it will log a message.
|
||||
func (ft *Features) DisableList(list []string) *Features {
|
||||
for _, feature := range list {
|
||||
ft.Disable(strings.TrimSpace(feature))
|
||||
}
|
||||
return ft
|
||||
}
|
||||
|
||||
// Fill fills in the function pointers in the Features struct from the
|
||||
// optional interfaces. It returns the original updated Features
|
||||
// struct passed in.
|
||||
@@ -387,7 +429,7 @@ func (ft *Features) Fill(f Fs) *Features {
|
||||
if do, ok := f.(ListRer); ok {
|
||||
ft.ListR = do.ListR
|
||||
}
|
||||
return ft
|
||||
return ft.DisableList(Config.DisableFeatures)
|
||||
}
|
||||
|
||||
// Mask the Features with the Fs passed in
|
||||
@@ -438,7 +480,7 @@ func (ft *Features) Mask(f Fs) *Features {
|
||||
if mask.ListR == nil {
|
||||
ft.ListR = nil
|
||||
}
|
||||
return ft
|
||||
return ft.DisableList(Config.DisableFeatures)
|
||||
}
|
||||
|
||||
// Wrap makes a Copy of the features passed in, overriding the UnWrap
|
||||
|
||||
Reference in New Issue
Block a user