Skip to content

Commit

Permalink
koofr: use lib/encoder
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Craig-Wood <nick@craig-wood.com>
  • Loading branch information
B4dM4n and ncw committed Sep 30, 2019
1 parent ace15c2 commit 9feceae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/koofr/koofr.go
Expand Up @@ -15,12 +15,15 @@ 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/hash"

httpclient "github.com/koofr/go-httpclient"
koofrclient "github.com/koofr/go-koofrclient"
)

const enc = encodings.Koofr

// Register Fs with rclone
func init() {
fs.Register(&fs.RegInfo{
Expand Down Expand Up @@ -242,7 +245,7 @@ func (f *Fs) Hashes() hash.Set {

// fullPath constructs a full, absolute path from a Fs root relative path,
func (f *Fs) fullPath(part string) string {
return path.Join("/", f.root, part)
return enc.FromStandardPath(path.Join("/", f.root, part))
}

// NewFs constructs a new filesystem given a root path and configuration options
Expand Down Expand Up @@ -293,7 +296,7 @@ func NewFs(name, root string, m configmap.Mapper) (ff fs.Fs, err error) {
}
return nil, errors.New("Failed to find mount " + opt.MountID)
}
rootFile, err := f.client.FilesInfo(f.mountID, "/"+f.root)
rootFile, err := f.client.FilesInfo(f.mountID, enc.FromStandardPath("/"+f.root))
if err == nil && rootFile.Type != "dir" {
f.root = dir(f.root)
err = fs.ErrorIsFile
Expand All @@ -311,13 +314,14 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
}
entries = make([]fs.DirEntry, len(files))
for i, file := range files {
remote := path.Join(dir, enc.ToStandardName(file.Name))
if file.Type == "dir" {
entries[i] = fs.NewDir(path.Join(dir, file.Name), time.Unix(0, 0))
entries[i] = fs.NewDir(remote, time.Unix(0, 0))
} else {
entries[i] = &Object{
fs: f,
info: file,
remote: path.Join(dir, file.Name),
remote: remote,
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions docs/content/koofr.md
Expand Up @@ -86,6 +86,18 @@ To copy a local directory to an Koofr directory called backup

rclone copy /home/source remote:backup

#### Restricted filename characters

In addition to the [default restricted characters set](/overview/#restricted-characters)
the following characters are also replaced:

| Character | Value | Replacement |
| --------- |:-----:|:-----------:|
| \ | 0x5C ||

Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8),
as they can't be used in XML strings.

<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/koofr/koofr.go then run make backenddocs -->
### Standard Options

Expand Down

0 comments on commit 9feceae

Please sign in to comment.