Skip to content

Commit

Permalink
fic copy
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Jul 31, 2024
1 parent 4e17290 commit 2ab9b01
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions backend/icloud/icloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,50 +380,46 @@ 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")
return nil, fs.ErrorCantCopy
}

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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2ab9b01

Please sign in to comment.