From 2ab9b019c9f2672f77d6b12050ec49dd375bc39e Mon Sep 17 00:00:00 2001 From: lostb1t Date: Wed, 31 Jul 2024 14:05:06 +0200 Subject: [PATCH] fic copy --- backend/icloud/icloud.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/backend/icloud/icloud.go b/backend/icloud/icloud.go index fa6a9f1f998b6..b12e3aa417623 100644 --- a/backend/icloud/icloud.go +++ b/backend/icloud/icloud.go @@ -380,8 +380,7 @@ func (f *Fs) Precision() time.Duration { // // If it isn't possible then return fs.ErrorCantCopy func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) { - // note: so many calls its only faster then a reupload for big files. - + // note: so many calls its only just faster then a reupload for big files. srcObj, ok := src.(*Object) if !ok { fs.Debugf(src, "Can't copy - not same remote type") @@ -389,41 +388,38 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, } dir, file := filepath.Split(remote) - - // var pathID string - _, pathID, _, err := f.FindPath(ctx, dir, true) + pathID, _, err := f.FindDir(ctx, dir, true) if err != nil { return nil, err } - service, _ := f.icloud.DriveService() var resp *http.Response var info *api.DriveItemRaw - //var item *api.DriveItem - // var err error + + // make a copy if err = f.pacer.Call(func() (bool, error) { - info, resp, err = service.CopyDocByItemID(ctx, srcObj.id) + info, resp, err = f.service.CopyDocByItemID(ctx, srcObj.id) return shouldRetry(ctx, resp, err) }); err != nil { return nil, err } - // renaming in CopyDocByID does not work :/ so do it the hard way + // renaming in CopyDocByID endpoint does not work :/ so do it the hard way // get new document var doc *api.Document if err = f.pacer.Call(func() (bool, error) { - doc, resp, err = service.GetDocByItemID(ctx, info.ItemID) + doc, resp, err = f.service.GetDocByItemID(ctx, info.ItemID) return shouldRetry(ctx, resp, err) }); err != nil { return nil, err } - //fmt.Println("YO", doc.ParentID) + // get parentdrive id var dirDoc *api.Document if err = f.pacer.Call(func() (bool, error) { - dirDoc, resp, err = service.GetDocByItemID(ctx, pathID) + dirDoc, resp, err = f.service.GetDocByItemID(ctx, pathID) return shouldRetry(ctx, resp, err) }); err != nil { return nil, err @@ -445,7 +441,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, var item *api.DriveItem if err = f.pacer.Call(func() (bool, error) { - item, resp, err = service.UpdateFile(ctx, &r) + item, resp, err = f.service.UpdateFile(ctx, &r) return shouldRetry(ctx, resp, err) }); err != nil { return nil, err @@ -680,7 +676,7 @@ func (f *Fs) move(ctx context.Context, ID, srcDirectoryID, srcLeaf, srcEtag, dst var resp *http.Response var item *api.DriveItem var err error - + //fmt.Println("MOVE") // move if srcDirectoryID != dstDirectoryID { if err = f.pacer.Call(func() (bool, error) { @@ -710,7 +706,7 @@ func (f *Fs) move(ctx context.Context, ID, srcDirectoryID, srcLeaf, srcEtag, dst // Move moves the src object to the specified remote. func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, error) { - srcObj, ok := src.(*Object) + srcObj, ok := src.(*Object) if !ok { fs.Debugf(src, "Can't move - not same remote type") return nil, fs.ErrorCantMove @@ -726,6 +722,9 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } + //fmt.Println("MOVE", srcObj.Remote(), srcLeaf, remote, dstLeaf, f.root) + + item, err := f.move(ctx, srcObj.id, srcDirectoryID, srcLeaf, srcObj.etag, dstDirectoryID, dstLeaf) if err != nil { return src, err