"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
fs: add Features.Enabled to return map of enabled features by name
Nick Craig-Woode1cf551ded7c
diff --git a/fs/fs.go b/fs/fs.goindex ad412f1c7..aa055d663 100644--- a/fs/fs.go+++ b/fs/fs.go@@ -618,6 +618,26 @@ func (ft *Features) List() (out []string) {return out}+// Enabled returns a map of features with keys showing whether they+// are enabled or not+func (ft *Features) Enabled() (features map[string]bool) {+ v := reflect.ValueOf(ft).Elem()+ vType := v.Type()+ features = make(map[string]bool, v.NumField())+ for i := 0; i < v.NumField(); i++ {+ vName := vType.Field(i).Name+ field := v.Field(i)+ if field.Kind() == reflect.Func {+ // Can't compare functions+ features[vName] = !field.IsNil()+ } else {+ zero := reflect.Zero(field.Type())+ features[vName] = field.Interface() != zero.Interface()+ }+ }+ return features+}+// 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 {diff --git a/fs/fs_test.go b/fs/fs_test.goindex 0fd15c22d..aaaa20502 100644--- a/fs/fs_test.go+++ b/fs/fs_test.go@@ -41,6 +41,31 @@ func TestFeaturesList(t *testing.T) {assert.True(t, strings.Contains(names, ",Copy,"))}+func TestFeaturesEnabled(t *testing.T) {+ ft := new(Features)+ ft.CaseInsensitive = true+ ft.Purge = func() error { return nil }+ enabled := ft.Enabled()++ flag, ok := enabled["CaseInsensitive"]+ assert.Equal(t, true, ok)+ assert.Equal(t, true, flag, enabled)++ flag, ok = enabled["Purge"]+ assert.Equal(t, true, ok)+ assert.Equal(t, true, flag, enabled)++ flag, ok = enabled["DuplicateFiles"]+ assert.Equal(t, true, ok)+ assert.Equal(t, false, flag, enabled)++ flag, ok = enabled["Copy"]+ assert.Equal(t, true, ok)+ assert.Equal(t, false, flag, enabled)++ assert.Equal(t, len(ft.List()), len(enabled))+}+func TestFeaturesDisableList(t *testing.T) {ft := new(Features)ft.Copy = func(src Object, remote string) (Object, error) {