mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
encoder/filename: Wrap scsu package
This commit is contained in:
parent
f14220ef1e
commit
5ca7f1fe87
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/dop251/scsu"
|
||||
"github.com/klauspost/compress/huff0"
|
||||
)
|
||||
|
||||
|
@ -51,7 +50,7 @@ func DecodeBytes(table byte, data []byte) (string, error) {
|
|||
case tableReserved:
|
||||
return "", ErrUnsupported
|
||||
case tableSCSUPlain:
|
||||
return scsu.Decode(data)
|
||||
return scsuDecode(data)
|
||||
case tableRLE:
|
||||
if len(data) < 2 {
|
||||
return "", ErrCorrupted
|
||||
|
@ -88,7 +87,7 @@ func DecodeBytes(table byte, data []byte) (string, error) {
|
|||
return "", ErrCorrupted
|
||||
}
|
||||
if table == tableSCSU {
|
||||
return scsu.Decode(name)
|
||||
return scsuDecode(name)
|
||||
}
|
||||
return string(name), nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package filename
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
@ -117,6 +120,10 @@ func TestDecode(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Decode(tt.encoded)
|
||||
if (err != nil) != tt.wantErr {
|
||||
if err != nil && err.Error() == scsuNotEnabled && runtime.Version() < "go1.13" {
|
||||
t.Skip(err.Error())
|
||||
return
|
||||
}
|
||||
if tt.encoded == "" && tt.want != "" {
|
||||
proposed := Encode(tt.want)
|
||||
table := decodeMap[proposed[0]] - 1
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/dop251/scsu"
|
||||
"github.com/klauspost/compress/huff0"
|
||||
)
|
||||
|
||||
|
@ -38,7 +37,7 @@ func EncodeBytes(s string) (table byte, payload []byte) {
|
|||
if i == tableSCSU {
|
||||
var err error
|
||||
olen := len(org)
|
||||
org, err = scsu.EncodeStrict(s, make([]byte, 0, len(org)))
|
||||
org, err = scsuEncodeStrict(s, make([]byte, 0, len(org)))
|
||||
if err != nil || olen <= len(org) {
|
||||
continue
|
||||
}
|
||||
|
|
16
lib/encoder/filename/scsu.go
Normal file
16
lib/encoder/filename/scsu.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package filename
|
||||
|
||||
import "errors"
|
||||
|
||||
const scsuNotEnabled = "scsu encoding not enabled in this build due to old go version"
|
||||
|
||||
// Functions wrap scsu package, since it doesn't build on old Go versions.
|
||||
// Remove once v1.13 is minimum supported version.
|
||||
|
||||
var scsuDecode = func(b []byte) (string, error) {
|
||||
return "", errors.New(scsuNotEnabled)
|
||||
}
|
||||
|
||||
var scsuEncodeStrict = func(src string, dst []byte) ([]byte, error) {
|
||||
return nil, errors.New(scsuNotEnabled)
|
||||
}
|
10
lib/encoder/filename/scsu_go113.go
Normal file
10
lib/encoder/filename/scsu_go113.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// +build go1.13
|
||||
|
||||
package filename
|
||||
|
||||
import "github.com/dop251/scsu"
|
||||
|
||||
func init() {
|
||||
scsuDecode = scsu.Decode
|
||||
scsuEncodeStrict = scsu.EncodeStrict
|
||||
}
|
Loading…
Reference in New Issue
Block a user