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:
Nick Craig-Wood
2017-08-07 21:10:03 +01:00
parent bced73c947
commit ec2ea37ad2
5 changed files with 132 additions and 5 deletions

View File

@@ -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