From 61497a90b6ab3ec1f5b54c99c13327127a09cfaf Mon Sep 17 00:00:00 2001 From: huanghaoyuan Date: Wed, 15 Nov 2023 13:45:28 +0800 Subject: [PATCH] storage: check file length after copy Signed-off-by: huanghaoyuan --- storage/copier.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/storage/copier.go b/storage/copier.go index 234da0f..c44932d 100644 --- a/storage/copier.go +++ b/storage/copier.go @@ -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) }