From 3304bb7a56cd688e09353ed1cabe8d255a46ef9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Sun, 19 May 2019 17:54:46 +0200 Subject: [PATCH] googlecloudstorage: use lib/encoder Co-authored-by: Nick Craig-Wood --- .../googlecloudstorage/googlecloudstorage.go | 17 ++++++++++++----- docs/content/googlecloudstorage.md | 12 ++++++++++++ fs/encodings/encodings.go | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go index 78754a655..d7f647555 100644 --- a/backend/googlecloudstorage/googlecloudstorage.go +++ b/backend/googlecloudstorage/googlecloudstorage.go @@ -32,6 +32,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/fshttp" "github.com/rclone/rclone/fs/hash" @@ -68,6 +69,8 @@ var ( } ) +const enc = encodings.GoogleCloudStorage + // Register with Fs func init() { fs.Register(&fs.RegInfo{ @@ -349,7 +352,8 @@ func parsePath(path string) (root string) { // split returns bucket and bucketPath from the rootRelativePath // relative to f.root func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) { - return bucket.Split(path.Join(f.root, rootRelativePath)) + bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath)) + return enc.FromStandardName(bucketName), enc.FromStandardPath(bucketPath) } // split returns bucket and bucketPath from the object @@ -438,8 +442,9 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) { if f.rootBucket != "" && f.rootDirectory != "" { // Check to see if the object exists + encodedDirectory := enc.FromStandardPath(f.rootDirectory) err = f.pacer.Call(func() (bool, error) { - _, err = f.svc.Objects.Get(f.rootBucket, f.rootDirectory).Context(ctx).Do() + _, err = f.svc.Objects.Get(f.rootBucket, encodedDirectory).Context(ctx).Do() return shouldRetry(err) }) if err == nil { @@ -522,6 +527,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck if !strings.HasSuffix(remote, "/") { continue } + remote = enc.ToStandardPath(remote) if !strings.HasPrefix(remote, prefix) { fs.Logf(f, "Odd name received %q", remote) continue @@ -537,11 +543,12 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck } } for _, object := range objects.Items { - if !strings.HasPrefix(object.Name, prefix) { + remote := enc.ToStandardPath(object.Name) + if !strings.HasPrefix(remote, prefix) { fs.Logf(f, "Odd name received %q", object.Name) continue } - remote := object.Name[len(prefix):] + remote = remote[len(prefix):] isDirectory := strings.HasSuffix(remote, "/") if addBucket { remote = path.Join(bucket, remote) @@ -613,7 +620,7 @@ func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error) return nil, err } for _, bucket := range buckets.Items { - d := fs.NewDir(bucket.Name, time.Time{}) + d := fs.NewDir(enc.ToStandardName(bucket.Name), time.Time{}) entries = append(entries, d) } if buckets.NextPageToken == "" { diff --git a/docs/content/googlecloudstorage.md b/docs/content/googlecloudstorage.md index 6ab4611c6..fe8977bec 100644 --- a/docs/content/googlecloudstorage.md +++ b/docs/content/googlecloudstorage.md @@ -221,6 +221,18 @@ Google google cloud storage stores md5sums natively and rclone stores modification times as metadata on the object, under the "mtime" key in RFC3339 format accurate to 1ns. +#### Restricted filename characters + +| Character | Value | Replacement | +| --------- |:-----:|:-----------:| +| NUL | 0x00 | ␀ | +| LF | 0x0A | ␊ | +| CR | 0x0D | ␍ | +| / | 0x2F | / | + +Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8), +as they can't be used in JSON strings. + ### Standard Options diff --git a/fs/encodings/encodings.go b/fs/encodings/encodings.go index d30538583..8b9ea5b6e 100644 --- a/fs/encodings/encodings.go +++ b/fs/encodings/encodings.go @@ -112,7 +112,7 @@ const Dropbox = encoder.MultiEncoder( // GoogleCloudStorage is the encoding used by the googlecloudstorage backend const GoogleCloudStorage = encoder.MultiEncoder( uint(Base) | - //encoder.EncodeCrLF | + encoder.EncodeCrLf | encoder.EncodeInvalidUtf8) // JottaCloud is the encoding used by the jottacloud backend