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.
This commit is contained in:
wiserain 2024-07-08 10:37:42 +09:00 committed by GitHub
parent bd5799c079
commit 6507770014
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1016,6 +1016,7 @@ func (f *Fs) createObject(ctx context.Context, remote string, modTime time.Time,
o = &Object{ o = &Object{
fs: f, fs: f,
remote: remote, remote: remote,
parent: dirID,
size: size, size: size,
modTime: modTime, modTime: modTime,
linkMu: new(sync.Mutex), 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 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) dstObj, dstLeaf, dstParentID, err := f.createObject(ctx, remote, srcObj.modTime, srcObj.size)
if err != nil { if err != nil {
return nil, err 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 { if err := f.copyObjects(ctx, []string{srcObj.id}, dstParentID); err != nil {
return nil, fmt.Errorf("couldn't copy file: %w", err) 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 // Can't copy and change name in one step so we have to check if we have
// the correct name after copy // 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 { if err != nil {
return nil, fmt.Errorf("copy: couldn't rename copied file: %w", err) return nil, fmt.Errorf("copy: couldn't rename copied file: %w", err)
} }
err = dstObj.setMetaData(info) return dstObj, 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, nil return dstObj, nil
} }