From 65077700141bbf65f2a44d2e16c1248bc334625f Mon Sep 17 00:00:00 2001 From: wiserain Date: Mon, 8 Jul 2024 10:37:42 +0900 Subject: [PATCH] pikpak: fix error with `copyto` command Fixes an issue where copied files could not be renamed when using the `copyto` command. This occurred because the object ID was empty before calling `readMetaData`. The fix preemptively calls `readMetaData` to ensure an object ID is available before attempting the rename operation. --- backend/pikpak/pikpak.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/pikpak/pikpak.go b/backend/pikpak/pikpak.go index 5fca36658..2095a391d 100644 --- a/backend/pikpak/pikpak.go +++ b/backend/pikpak/pikpak.go @@ -1016,6 +1016,7 @@ func (f *Fs) createObject(ctx context.Context, remote string, modTime time.Time, o = &Object{ fs: f, remote: remote, + parent: dirID, size: size, modTime: modTime, linkMu: new(sync.Mutex), @@ -1117,7 +1118,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } - // Create temporary object + // Create temporary object - still missing id, mimeType, gcid, md5sum dstObj, dstLeaf, dstParentID, err := f.createObject(ctx, remote, srcObj.modTime, srcObj.size) if err != nil { return nil, err @@ -1131,6 +1132,12 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, if err := f.copyObjects(ctx, []string{srcObj.id}, dstParentID); err != nil { return nil, fmt.Errorf("couldn't copy file: %w", err) } + // Update info of the copied object with new parent but source name + if info, err := dstObj.fs.readMetaDataForPath(ctx, srcObj.remote); err != nil { + return nil, fmt.Errorf("copy: couldn't locate copied file: %w", err) + } else if err = dstObj.setMetaData(info); err != nil { + return nil, err + } // Can't copy and change name in one step so we have to check if we have // the correct name after copy @@ -1145,16 +1152,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, if err != nil { return nil, fmt.Errorf("copy: couldn't rename copied file: %w", err) } - err = dstObj.setMetaData(info) - if err != nil { - return nil, err - } - } else { - // Update info - err = dstObj.readMetaData(ctx) - if err != nil { - return nil, fmt.Errorf("copy: couldn't locate copied file: %w", err) - } + return dstObj, dstObj.setMetaData(info) } return dstObj, nil }