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
This commit is contained in:
Nick Craig-Wood 2021-10-31 19:07:43 +00:00
parent 07fcba888c
commit f7764a0c9d
2 changed files with 16 additions and 8 deletions

View File

@ -58,6 +58,7 @@ type FolderListResponse struct {
Content []Item `json:"content"` Content []Item `json:"content"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
ParentID string `json:"parent_id,omitempty"` ParentID string `json:"parent_id,omitempty"`
FolderID string `json:"folder_id,omitempty"`
} }
// FolderCreateResponse is the response to folder/create // FolderCreateResponse is the response to folder/create

View File

@ -193,7 +193,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string, directoriesOn
} }
lcLeaf := strings.ToLower(leaf) 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 { if strings.ToLower(item.Name) == lcLeaf {
info = item info = item
return true 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 // 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) { func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut string, found bool, err error) {
// Find the leaf in pathID // 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) { if strings.EqualFold(item.Name, leaf) {
pathIDOut = item.ID pathIDOut = item.ID
return true return true
} }
return false return false
}) })
// Update the Root directory ID to its actual value
if pathID == rootID {
f.dirCache.SetRootIDAlias(newDirID)
}
return pathIDOut, found, err 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 // 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 // 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{ opts := rest.Opts{
Method: "GET", Method: "GET",
Path: "/folder/list", Path: "/folder/list",
@ -413,11 +420,12 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
return shouldRetry(ctx, resp, err) return shouldRetry(ctx, resp, err)
}) })
if err != nil { 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 { 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 { for i := range result.Content {
item := &result.Content[i] item := &result.Content[i]
if item.Type == api.ItemTypeFolder { if item.Type == api.ItemTypeFolder {
@ -438,7 +446,6 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
break break
} }
} }
return return
} }
@ -457,7 +464,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
return nil, err return nil, err
} }
var iErr error 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) remote := path.Join(dir, info.Name)
if info.Type == api.ItemTypeFolder { if info.Type == api.ItemTypeFolder {
// cache the directory ID for later lookups // 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 // need to check if empty as it will delete recursively by default
if check { 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 return true
}) })
if err != nil { if err != nil {