diff --git a/backend/s3/s3_internal_test.go b/backend/s3/s3_internal_test.go index d4b4e1e17..f48045072 100644 --- a/backend/s3/s3_internal_test.go +++ b/backend/s3/s3_internal_test.go @@ -318,7 +318,7 @@ func (f *Fs) InternalTestVersions(t *testing.T) { // Check we can make a NewFs from that object with a version suffix t.Run("NewFs", func(t *testing.T) { - newPath := bucket.Join(fs.ConfigString(f), fileNameVersion) + newPath := bucket.Join(fs.ConfigStringFull(f), fileNameVersion) // Make sure --s3-versions is set in the config of the new remote fs.Debugf(nil, "oldPath = %q", newPath) lastColon := strings.LastIndex(newPath, ":") @@ -330,7 +330,7 @@ func (f *Fs) InternalTestVersions(t *testing.T) { require.Equal(t, fs.ErrorIsFile, err) require.NotNil(t, fNew) // With the directory the directory above - assert.Equal(t, dirName, path.Base(fs.ConfigString(fNew))) + assert.Equal(t, dirName, path.Base(fs.ConfigStringFull(fNew))) }) }) diff --git a/fs/newfs.go b/fs/newfs.go index 52375e86e..9be890ec7 100644 --- a/fs/newfs.go +++ b/fs/newfs.go @@ -115,11 +115,11 @@ func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, conne return fsInfo, configName, fsPath, parsed.Config, err } -// ConfigString returns a canonical version of the config string used +// configString returns a canonical version of the config string used // to configure the Fs as passed to fs.NewFs -func ConfigString(f Fs) string { +func configString(f Fs, full bool) string { name := f.Name() - if open := strings.IndexRune(name, '{'); open >= 0 && strings.HasSuffix(name, "}") { + if open := strings.IndexRune(name, '{'); full && open >= 0 && strings.HasSuffix(name, "}") { suffix := name[open:] overriddenConfigMu.Lock() config, ok := overriddenConfig[suffix] @@ -137,6 +137,21 @@ func ConfigString(f Fs) string { return name + ":" + root } +// ConfigString returns a canonical version of the config string used +// to configure the Fs as passed to fs.NewFs. For Fs with extra +// parameters this will include a canonical {hexstring} suffix. +func ConfigString(f Fs) string { + return configString(f, false) +} + +// ConfigStringFull returns a canonical version of the config string +// used to configure the Fs as passed to fs.NewFs. This string can be +// used to re-instantiate the Fs exactly so includes all the extra +// parameters passed in. +func ConfigStringFull(f Fs) string { + return configString(f, true) +} + // TemporaryLocalFs creates a local FS in the OS's temporary directory. // // No cleanup is performed, the caller must call Purge on the Fs themselves. diff --git a/fs/newfs_test.go b/fs/newfs_test.go index 3f86cd2d5..4d5ef8520 100644 --- a/fs/newfs_test.go +++ b/fs/newfs_test.go @@ -32,12 +32,14 @@ func TestNewFs(t *testing.T) { assert.Equal(t, ":mockfs{S_NHG}", f2.Name()) assert.Equal(t, "/tmp", f2.Root()) - assert.Equal(t, ":mockfs,potato='true':/tmp", fs.ConfigString(f2)) + assert.Equal(t, ":mockfs{S_NHG}:/tmp", fs.ConfigString(f2)) + assert.Equal(t, ":mockfs,potato='true':/tmp", fs.ConfigStringFull(f2)) f3, err := fs.NewFs(ctx, ":mockfs,potato='true':/tmp") require.NoError(t, err) assert.Equal(t, ":mockfs{S_NHG}", f3.Name()) assert.Equal(t, "/tmp", f3.Root()) - assert.Equal(t, ":mockfs,potato='true':/tmp", fs.ConfigString(f3)) + assert.Equal(t, ":mockfs{S_NHG}:/tmp", fs.ConfigString(f3)) + assert.Equal(t, ":mockfs,potato='true':/tmp", fs.ConfigStringFull(f3)) }