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

storage: check file length after copy #71

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading