Skip to content

Commit

Permalink
sharefile: use lib/encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed Sep 30, 2019
1 parent 45dc8ea commit ace15c2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 114 deletions.
76 changes: 0 additions & 76 deletions backend/sharefile/replace.go

This file was deleted.

31 changes: 0 additions & 31 deletions backend/sharefile/replace_test.go

This file was deleted.

17 changes: 10 additions & 7 deletions backend/sharefile/sharefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import (
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure"
"github.com/rclone/rclone/fs/encodings"
"github.com/rclone/rclone/fs/fserrors"
"github.com/rclone/rclone/fs/hash"
"github.com/rclone/rclone/lib/dircache"
Expand All @@ -100,6 +101,8 @@ import (
"golang.org/x/oauth2"
)

const enc = encodings.Sharefile

const (
rcloneClientID = "djQUPlHTUM9EvayYBWuKC5IrVIoQde46"
rcloneEncryptedClientSecret = "v7572bKhUindQL3yDnUAebmgP-QxiwT38JLxVPolcZBl6SSs329MtFzH73x7BeELmMVZtneUPvALSopUZ6VkhQ"
Expand Down Expand Up @@ -298,7 +301,7 @@ func (f *Fs) readMetaDataForIDPath(ctx context.Context, id, path string, directo
}
if path != "" {
opts.Path += "/ByPath"
opts.Parameters.Set("path", "/"+replaceReservedChars(path))
opts.Parameters.Set("path", "/"+enc.FromStandardPath(path))
}
var item api.Item
var resp *http.Response
Expand Down Expand Up @@ -592,7 +595,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
// CreateDir makes a directory with pathID as parent and name leaf
func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error) {
var resp *http.Response
leaf = replaceReservedChars(leaf)
leaf = enc.FromStandardName(leaf)
var req = api.Item{
Name: leaf,
FileName: leaf,
Expand Down Expand Up @@ -661,7 +664,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
continue
}
item.Name = restoreReservedChars(item.Name)
item.Name = enc.ToStandardName(item.Name)
if fn(item) {
found = true
break
Expand Down Expand Up @@ -870,7 +873,7 @@ func (f *Fs) updateItem(ctx context.Context, id, leaf, directoryID string, modTi
"overwrite": {"false"},
},
}
leaf = replaceReservedChars(leaf)
leaf = enc.FromStandardName(leaf)
// FIXME this appears to be a bug in the API
//
// If you set the modified time via PATCH then the server
Expand Down Expand Up @@ -1116,15 +1119,15 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (dst fs.Obj
if err != nil {
return nil, err
}
srcLeaf = replaceReservedChars(srcLeaf)
srcLeaf = enc.FromStandardName(srcLeaf)
_ = srcParentID

// Create temporary object
dstObj, dstLeaf, dstParentID, err := f.createObject(ctx, remote, srcObj.modTime, srcObj.size)
if err != nil {
return nil, err
}
dstLeaf = replaceReservedChars(dstLeaf)
dstLeaf = enc.FromStandardName(dstLeaf)

sameName := strings.ToLower(srcLeaf) == strings.ToLower(dstLeaf)
if sameName && srcParentID == dstParentID {
Expand Down Expand Up @@ -1387,7 +1390,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
if err != nil {
return err
}
leaf = replaceReservedChars(leaf)
leaf = enc.FromStandardName(leaf)
var req = api.UploadRequest{
Method: "standard",
Raw: true,
Expand Down
15 changes: 15 additions & 0 deletions fs/encodings/encodings.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ const QingStor = encoder.MultiEncoder(
encoder.EncodeCtl |
encoder.EncodeSlash)

// Sharefile is the encoding used by the sharefile backend
const Sharefile = encoder.MultiEncoder(
uint(Base) |
encoder.EncodeWin | // :?"*<>|
encoder.EncodeBackSlash | // \
encoder.EncodeCtl |
encoder.EncodeRightSpace |
encoder.EncodeRightPeriod |
encoder.EncodeLeftSpace |
encoder.EncodeLeftPeriod |
encoder.EncodeInvalidUtf8)

// ByName returns the encoder for a give backend name or nil
func ByName(name string) encoder.Encoder {
switch strings.ToLower(name) {
Expand Down Expand Up @@ -353,6 +365,8 @@ func ByName(name string) encoder.Encoder {
return QingStor
case "s3":
return S3
case "sharefile":
return Sharefile
//case "sftp":
case "swift":
return Swift
Expand Down Expand Up @@ -392,5 +406,6 @@ func Names() []string {
"onedrive",
"opendrive",
"pcloud",
"sharefile",
}
}

0 comments on commit ace15c2

Please sign in to comment.