From 0931b84940146a24e4768cc0a50eccda8c03e8f4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 20 Aug 2020 20:09:55 +0100 Subject: [PATCH] pcloud: Fix rclone link for files This was only working for files in the root directory and wasn't looking at the encoding. This is fixed to use NewObject which takes both things into account and it makes the share by ID instead of by path. This problem was spotted by the integration tests. --- backend/pcloud/pcloud.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go index 42a4e5b3e..d46b1ea71 100644 --- a/backend/pcloud/pcloud.go +++ b/backend/pcloud/pcloud.go @@ -814,14 +814,19 @@ func (f *Fs) linkDir(ctx context.Context, dirID string, expire fs.Duration) (str } func (f *Fs) linkFile(ctx context.Context, path string, expire fs.Duration) (string, error) { + obj, err := f.NewObject(ctx, path) + if err != nil { + return "", err + } + o := obj.(*Object) opts := rest.Opts{ Method: "POST", Path: "/getfilepublink", Parameters: url.Values{}, } var result api.PubLinkResult - opts.Parameters.Set("path", path) - err := f.pacer.Call(func() (bool, error) { + opts.Parameters.Set("fileid", fileIDtoNumber(o.id)) + err = f.pacer.Call(func() (bool, error) { resp, err := f.srv.CallJSON(ctx, &opts, nil, &result) err = result.Error.Update(err) return shouldRetry(resp, err) @@ -834,11 +839,6 @@ func (f *Fs) linkFile(ctx context.Context, path string, expire fs.Duration) (str // PublicLink adds a "readable by anyone with link" permission on the given file or folder. func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (string, error) { - err := f.dirCache.FindRoot(ctx, false) - if err != nil { - return "", err - } - dirID, err := f.dirCache.FindDir(ctx, remote, false) if err == fs.ErrorDirNotFound { return f.linkFile(ctx, remote, expire)