mirror of
https://github.com/rclone/rclone
synced 2024-12-27 19:43:48 +01:00
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:
parent
bd5799c079
commit
6507770014
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user