Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
storage: check file length after copy
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuan <[email protected]>
  • Loading branch information
huanghaoyuanhhy committed Nov 15, 2023
1 parent 1324866 commit 61497a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions storage/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,22 @@ func (c *Copier) CopyPrefix(ctx context.Context, i CopyPathInput) error {
attr := srcAttr
job := func(ctx context.Context) error {
destKey := i.DestKeyFn(attr)
// copy
destAttr, err := c.dest.HeadObject(ctx, i.DestBucket, destKey)
if err != nil || !attr.SameAs(destAttr) {
if err := fn(ctx, attr, destKey, i.SrcBucket, i.DestBucket); err != nil {
return fmt.Errorf("storage: copier copy object %w", err)
}
}
// check
destAttr, err = c.dest.HeadObject(ctx, i.DestBucket, destKey)
if err != nil {
return fmt.Errorf("storage: after copy %w", err)
}
if destAttr.Length != attr.Length {
return fmt.Errorf("storage: dest len %d != src len %d", destAttr.Length, attr.Length)
}

if i.OnSuccess != nil {
i.OnSuccess(attr)
}
Expand Down

0 comments on commit 61497a9

Please sign in to comment.