mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 23:22:08 +01:00
pikpak: fix cid/gcid calculations for fs.OverrideRemote
Previously, cid/gcid (custom hash for pikpak) calculations failed when attempting to unwrap object info from `fs.OverrideRemote`. This commit introduces a new function that can correctly unwrap object info from both regular objects and `fs.OverrideRemote` types, ensuring uploads with accurate cid/gcid calculations in all scenarios.
This commit is contained in:
parent
06ae0dfa54
commit
6d04be99f2
@ -378,11 +378,23 @@ func calcGcid(r io.Reader, size int64) (string, error) {
|
|||||||
return hex.EncodeToString(totalHash.Sum(nil)), nil
|
return hex.EncodeToString(totalHash.Sum(nil)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unWrapObjectInfo returns the underlying Object unwrapped as much as
|
||||||
|
// possible or nil even if it is an OverrideRemote
|
||||||
|
func unWrapObjectInfo(oi fs.ObjectInfo) fs.Object {
|
||||||
|
if o, ok := oi.(fs.Object); ok {
|
||||||
|
return fs.UnWrapObject(o)
|
||||||
|
} else if do, ok := oi.(*fs.OverrideRemote); ok {
|
||||||
|
// Unwrap if it is an operations.OverrideRemote
|
||||||
|
return do.UnWrap()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// calcCid calculates Cid from source
|
// calcCid calculates Cid from source
|
||||||
//
|
//
|
||||||
// Cid is a simplified version of Gcid
|
// Cid is a simplified version of Gcid
|
||||||
func calcCid(ctx context.Context, src fs.ObjectInfo) (cid string, err error) {
|
func calcCid(ctx context.Context, src fs.ObjectInfo) (cid string, err error) {
|
||||||
srcObj := fs.UnWrapObjectInfo(src)
|
srcObj := unWrapObjectInfo(src)
|
||||||
if srcObj == nil {
|
if srcObj == nil {
|
||||||
return "", fmt.Errorf("failed to unwrap object from src: %s", src)
|
return "", fmt.Errorf("failed to unwrap object from src: %s", src)
|
||||||
}
|
}
|
||||||
|
@ -1773,7 +1773,7 @@ func (o *Object) upload(ctx context.Context, in io.Reader, src fs.ObjectInfo, wi
|
|||||||
gcid, err := o.fs.getGcid(ctx, src)
|
gcid, err := o.fs.getGcid(ctx, src)
|
||||||
if err != nil || gcid == "" {
|
if err != nil || gcid == "" {
|
||||||
fs.Debugf(o, "calculating gcid: %v", err)
|
fs.Debugf(o, "calculating gcid: %v", err)
|
||||||
if srcObj := fs.UnWrapObjectInfo(src); srcObj != nil && srcObj.Fs().Features().IsLocal {
|
if srcObj := unWrapObjectInfo(src); srcObj != nil && srcObj.Fs().Features().IsLocal {
|
||||||
// No buffering; directly calculate gcid from source
|
// No buffering; directly calculate gcid from source
|
||||||
rc, err := srcObj.Open(ctx)
|
rc, err := srcObj.Open(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user