From f7764a0c9d2f5a9418ffe3949bf16c6584c384ee Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 31 Oct 2021 19:07:43 +0000 Subject: [PATCH] premiumizeme: fix server side directory move after API changes Apparently moving a directory using the id "0" as the root no longer works, so this reads the real root ID when it is listed and uses that. This fixes the DirMove problem. See: https://forum.rclone.org/t/premiumize-cant-move-files/27169 See: #5734 --- backend/premiumizeme/api/types.go | 1 + backend/premiumizeme/premiumizeme.go | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/premiumizeme/api/types.go b/backend/premiumizeme/api/types.go index 1dccd4ff9..45c65fd1b 100644 --- a/backend/premiumizeme/api/types.go +++ b/backend/premiumizeme/api/types.go @@ -58,6 +58,7 @@ type FolderListResponse struct { Content []Item `json:"content"` Name string `json:"name,omitempty"` ParentID string `json:"parent_id,omitempty"` + FolderID string `json:"folder_id,omitempty"` } // FolderCreateResponse is the response to folder/create diff --git a/backend/premiumizeme/premiumizeme.go b/backend/premiumizeme/premiumizeme.go index 71c02a8cc..9f152a3f8 100644 --- a/backend/premiumizeme/premiumizeme.go +++ b/backend/premiumizeme/premiumizeme.go @@ -193,7 +193,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string, directoriesOn } lcLeaf := strings.ToLower(leaf) - found, err := f.listAll(ctx, directoryID, directoriesOnly, filesOnly, func(item *api.Item) bool { + _, found, err := f.listAll(ctx, directoryID, directoriesOnly, filesOnly, func(item *api.Item) bool { if strings.ToLower(item.Name) == lcLeaf { info = item return true @@ -345,13 +345,18 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) { // FindLeaf finds a directory of name leaf in the folder with ID pathID func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut string, found bool, err error) { // Find the leaf in pathID - found, err = f.listAll(ctx, pathID, true, false, func(item *api.Item) bool { + var newDirID string + newDirID, found, err = f.listAll(ctx, pathID, true, false, func(item *api.Item) bool { if strings.EqualFold(item.Name, leaf) { pathIDOut = item.ID return true } return false }) + // Update the Root directory ID to its actual value + if pathID == rootID { + f.dirCache.SetRootIDAlias(newDirID) + } return pathIDOut, found, err } @@ -395,7 +400,9 @@ type listAllFn func(*api.Item) bool // Lists the directory required calling the user function on each item found // // If the user fn ever returns true then it early exits with found = true -func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, filesOnly bool, fn listAllFn) (found bool, err error) { +// +// It returns a newDirID which is what the system returned as the directory ID +func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, filesOnly bool, fn listAllFn) (newDirID string, found bool, err error) { opts := rest.Opts{ Method: "GET", Path: "/folder/list", @@ -413,11 +420,12 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi return shouldRetry(ctx, resp, err) }) if err != nil { - return found, errors.Wrap(err, "couldn't list files") + return newDirID, found, errors.Wrap(err, "couldn't list files") } if err = result.AsErr(); err != nil { - return found, errors.Wrap(err, "error while listing") + return newDirID, found, errors.Wrap(err, "error while listing") } + newDirID = result.FolderID for i := range result.Content { item := &result.Content[i] if item.Type == api.ItemTypeFolder { @@ -438,7 +446,6 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi break } } - return } @@ -457,7 +464,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e return nil, err } var iErr error - _, err = f.listAll(ctx, directoryID, false, false, func(info *api.Item) bool { + _, _, err = f.listAll(ctx, directoryID, false, false, func(info *api.Item) bool { remote := path.Join(dir, info.Name) if info.Type == api.ItemTypeFolder { // cache the directory ID for later lookups @@ -561,7 +568,7 @@ func (f *Fs) purgeCheck(ctx context.Context, dir string, check bool) error { // need to check if empty as it will delete recursively by default if check { - found, err := f.listAll(ctx, rootID, false, false, func(item *api.Item) bool { + _, found, err := f.listAll(ctx, rootID, false, false, func(item *api.Item) bool { return true }) if err != nil {