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

local: refactor default os encoding out from local backend into shared encoder lib

albertony9a2811f0b2b0
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)