From 2c50f26c36e7b18e0fcfe18bc844a2141c9245af Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 20 Jun 2023 17:38:17 +0100 Subject: [PATCH] mount: fix mount failure on macOS with on the fly remote This commit 3567a47258c7c29a fs: make ConfigString properly reverse suffixed file systems made fs.ConfigString() return the full config of the backend. Because mount was using this to make a volume name it started to make volume names with illegal characters in which couldn't be mounted by macOS. This fixes the problem by making a separate fs.ConfigStringFull() and using that where appropriate and leaving the original fs.ConfigString() function untouched. Fixes #7063 See: https://forum.rclone.org/t/1-63-beta-fails-to-mount-on-macos-with-on-the-fly-crypt-remote/39090 --- backend/s3/s3_internal_test.go | 4 ++-- fs/newfs.go | 21 ++++++++++++++++++--- fs/newfs_test.go | 6 ++++-- 3 files changed, 24 insertions(+), 7 deletions(-) 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)) }