mirror of
https://github.com/rclone/rclone.git
synced 2025-02-02 11:39:33 +01:00
local: refactor default os encoding out from local backend into shared encoder lib
This commit is contained in:
parent
63708d73be
commit
9a2811f0b2
@ -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)
|
|
@ -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
|
|
@ -195,7 +195,7 @@ enabled, rclone will no longer update the modtime after copying a file.`,
|
|||||||
Name: config.ConfigEncoding,
|
Name: config.ConfigEncoding,
|
||||||
Help: config.ConfigEncodingHelp,
|
Help: config.ConfigEncodingHelp,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
Default: defaultEnc,
|
Default: encoder.OS,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
fs.Register(fsi)
|
fs.Register(fsi)
|
||||||
|
@ -3,6 +3,8 @@ package local
|
|||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test Windows character replacements
|
// Test Windows character replacements
|
||||||
@ -21,7 +23,7 @@ func TestCleanWindows(t *testing.T) {
|
|||||||
t.Skipf("windows only")
|
t.Skipf("windows only")
|
||||||
}
|
}
|
||||||
for _, test := range testsWindows {
|
for _, test := range testsWindows {
|
||||||
got := cleanRootPath(test[0], true, defaultEnc)
|
got := cleanRootPath(test[0], true, encoder.OS)
|
||||||
expect := test[1]
|
expect := test[1]
|
||||||
if got != expect {
|
if got != expect {
|
||||||
t.Fatalf("got %q, expected %q", got, expect)
|
t.Fatalf("got %q, expected %q", got, expect)
|
||||||
|
9
lib/encoder/os_darwin.go
Normal file
9
lib/encoder/os_darwin.go
Normal file
@ -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)
|
6
lib/encoder/os_other.go
Normal file
6
lib/encoder/os_other.go
Normal file
@ -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
|
@ -1,10 +1,8 @@
|
|||||||
//+build windows
|
//+build windows
|
||||||
|
|
||||||
package local
|
package encoder
|
||||||
|
|
||||||
import "github.com/rclone/rclone/lib/encoder"
|
// OS is the encoding used by the local backend for windows platforms
|
||||||
|
|
||||||
// This is the encoding used by the local backend for windows platforms
|
|
||||||
//
|
//
|
||||||
// List of replaced characters:
|
// List of replaced characters:
|
||||||
// < (less than) -> '<' // FULLWIDTH LESS-THAN SIGN
|
// < (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.
|
// 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
|
// https://docs.microsoft.com/de-de/windows/desktop/FileIO/naming-a-file#naming-conventions
|
||||||
const defaultEnc = (encoder.Base |
|
const OS = (Base |
|
||||||
encoder.EncodeWin |
|
EncodeWin |
|
||||||
encoder.EncodeBackSlash |
|
EncodeBackSlash |
|
||||||
encoder.EncodeCtl |
|
EncodeCtl |
|
||||||
encoder.EncodeRightSpace |
|
EncodeRightSpace |
|
||||||
encoder.EncodeRightPeriod |
|
EncodeRightPeriod |
|
||||||
encoder.EncodeInvalidUtf8)
|
EncodeInvalidUtf8)
|
Loading…
Reference in New Issue
Block a user