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.
This commit is contained in:
Nick Craig-Wood 2020-08-20 20:09:55 +01:00
parent 94a0991584
commit 0931b84940

View file

@ -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) { 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{ opts := rest.Opts{
Method: "POST", Method: "POST",
Path: "/getfilepublink", Path: "/getfilepublink",
Parameters: url.Values{}, Parameters: url.Values{},
} }
var result api.PubLinkResult var result api.PubLinkResult
opts.Parameters.Set("path", path) opts.Parameters.Set("fileid", fileIDtoNumber(o.id))
err := f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
resp, err := f.srv.CallJSON(ctx, &opts, nil, &result) resp, err := f.srv.CallJSON(ctx, &opts, nil, &result)
err = result.Error.Update(err) err = result.Error.Update(err)
return shouldRetry(resp, 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. // 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) { 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) dirID, err := f.dirCache.FindDir(ctx, remote, false)
if err == fs.ErrorDirNotFound { if err == fs.ErrorDirNotFound {
return f.linkFile(ctx, remote, expire) return f.linkFile(ctx, remote, expire)