From 9a2811f0b2b0aaf5bb060894186dca079dd7230e Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 28 May 2021 13:34:29 +0200 Subject: [PATCH] local: refactor default os encoding out from local backend into shared encoder lib --- backend/local/encode_darwin.go | 11 ---------- backend/local/encode_other.go | 8 -------- backend/local/local.go | 2 +- backend/local/tests_test.go | 4 +++- lib/encoder/os_darwin.go | 9 +++++++++ lib/encoder/os_other.go | 6 ++++++ .../encoder/os_windows.go | 20 +++++++++---------- 7 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 backend/local/encode_darwin.go delete mode 100644 backend/local/encode_other.go create mode 100644 lib/encoder/os_darwin.go create mode 100644 lib/encoder/os_other.go rename backend/local/encode_windows.go => lib/encoder/os_windows.go (73%) diff --git a/backend/local/encode_darwin.go b/backend/local/encode_darwin.go deleted file mode 100644 index e5615b318..000000000 --- a/backend/local/encode_darwin.go +++ /dev/null @@ -1,11 +0,0 @@ -//+build darwin - -package local - -import "github.com/rclone/rclone/lib/encoder" - -// This is the encoding used by the local backend for macOS -// -// macOS can't store invalid UTF-8, it converts them into %XX encoding -const defaultEnc = (encoder.Base | - encoder.EncodeInvalidUtf8) diff --git a/backend/local/encode_other.go b/backend/local/encode_other.go deleted file mode 100644 index 2fcafe84e..000000000 --- a/backend/local/encode_other.go +++ /dev/null @@ -1,8 +0,0 @@ -//+build !windows,!darwin - -package local - -import "github.com/rclone/rclone/lib/encoder" - -// This is the encoding used by the local backend for non windows platforms -const defaultEnc = encoder.Base diff --git a/backend/local/local.go b/backend/local/local.go index 85b167442..99c9c6f0f 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -195,7 +195,7 @@ enabled, rclone will no longer update the modtime after copying a file.`, Name: config.ConfigEncoding, Help: config.ConfigEncodingHelp, Advanced: true, - Default: defaultEnc, + Default: encoder.OS, }}, } fs.Register(fsi) diff --git a/backend/local/tests_test.go b/backend/local/tests_test.go index e67c72705..f85ea0f15 100644 --- a/backend/local/tests_test.go +++ b/backend/local/tests_test.go @@ -3,6 +3,8 @@ package local import ( "runtime" "testing" + + "github.com/rclone/rclone/lib/encoder" ) // Test Windows character replacements @@ -21,7 +23,7 @@ func TestCleanWindows(t *testing.T) { t.Skipf("windows only") } for _, test := range testsWindows { - got := cleanRootPath(test[0], true, defaultEnc) + got := cleanRootPath(test[0], true, encoder.OS) expect := test[1] if got != expect { t.Fatalf("got %q, expected %q", got, expect) diff --git a/lib/encoder/os_darwin.go b/lib/encoder/os_darwin.go new file mode 100644 index 000000000..7eb128bb2 --- /dev/null +++ b/lib/encoder/os_darwin.go @@ -0,0 +1,9 @@ +//+build darwin + +package encoder + +// OS is the encoding used by the local backend for macOS +// +// macOS can't store invalid UTF-8, it converts them into %XX encoding +const OS = (Base | + EncodeInvalidUtf8) diff --git a/lib/encoder/os_other.go b/lib/encoder/os_other.go new file mode 100644 index 000000000..32a916fb4 --- /dev/null +++ b/lib/encoder/os_other.go @@ -0,0 +1,6 @@ +//+build !windows,!darwin + +package encoder + +// OS is the encoding used by the local backend for non windows platforms +const OS = Base diff --git a/backend/local/encode_windows.go b/lib/encoder/os_windows.go similarity index 73% rename from backend/local/encode_windows.go rename to lib/encoder/os_windows.go index 68e87a914..d06b28243 100644 --- a/backend/local/encode_windows.go +++ b/lib/encoder/os_windows.go @@ -1,10 +1,8 @@ //+build windows -package local +package encoder -import "github.com/rclone/rclone/lib/encoder" - -// This is the encoding used by the local backend for windows platforms +// OS is the encoding used by the local backend for windows platforms // // List of replaced characters: // < (less than) -> '<' // FULLWIDTH LESS-THAN SIGN @@ -24,10 +22,10 @@ import "github.com/rclone/rclone/lib/encoder" // Also encode invalid UTF-8 bytes as Go can't convert them to UTF-16. // // https://docs.microsoft.com/de-de/windows/desktop/FileIO/naming-a-file#naming-conventions -const defaultEnc = (encoder.Base | - encoder.EncodeWin | - encoder.EncodeBackSlash | - encoder.EncodeCtl | - encoder.EncodeRightSpace | - encoder.EncodeRightPeriod | - encoder.EncodeInvalidUtf8) +const OS = (Base | + EncodeWin | + EncodeBackSlash | + EncodeCtl | + EncodeRightSpace | + EncodeRightPeriod | + EncodeInvalidUtf8)