Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs/rc: add Copy method to rc.Params

Nick Craig-Wood847a44e7ad68
diff --git a/fs/rc/params.go b/fs/rc/params.go
index 2684b5120..f9353de52 100644
--- a/fs/rc/params.go
+++ b/fs/rc/params.go
@@ -79,6 +79,15 @@ func Reshape(out interface{}, in interface{}) error {
return nil
}
+// Copy shallow copies the Params
+func (p Params) Copy() (out Params) {
+ out = make(Params, len(p))
+ for k, v := range p {
+ out[k] = v
+ }
+ return out
+}
+
// Get gets a parameter from the input
//
// If the parameter isn't found then error will be of type
diff --git a/fs/rc/params_test.go b/fs/rc/params_test.go
index e9b770c41..3006f08ce 100644
--- a/fs/rc/params_test.go
+++ b/fs/rc/params_test.go
@@ -63,6 +63,19 @@ func TestReshape(t *testing.T) {
}
+func TestParamsCopy(t *testing.T) {
+ in := Params{
+ "ok": 1,
+ "x": "seventeen",
+ "nil": nil,
+ }
+ out := in.Copy()
+ assert.Equal(t, in, out)
+ if &in == &out {
+ t.Error("didn't copy")
+ }
+}
+
func TestParamsGet(t *testing.T) {
in := Params{
"ok": 1,