From 699203de049a3ba3d50e3ebcc2498ab6d2b4b714 Mon Sep 17 00:00:00 2001 From: huanghaoyuanhhy Date: Tue, 26 Sep 2023 15:43:21 +0800 Subject: [PATCH] storage: do not copy empty file (#62) Signed-off-by: huanghaoyuan --- storage/client.go | 2 ++ storage/copier.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/storage/client.go b/storage/client.go index 0be018b..8b7455e 100644 --- a/storage/client.go +++ b/storage/client.go @@ -138,6 +138,8 @@ func (o *ObjectAttr) SameAs(other ObjectAttr) bool { return o.Length == other.Length && o.ETag == other.ETag } +func (o *ObjectAttr) IsEmpty() bool { return o.Length == 0 } + type Page struct { Contents []ObjectAttr } diff --git a/storage/copier.go b/storage/copier.go index 45ae59d..b6b9056 100644 --- a/storage/copier.go +++ b/storage/copier.go @@ -98,6 +98,7 @@ type CopyPathInput struct { OnSuccess func(attr ObjectAttr, total Total) } +// getAttrs get all attrs under bucket/prefix func (c *Copier) getAttrs(ctx context.Context, bucket, prefix string) ([]ObjectAttr, Total, error) { var attrs []ObjectAttr var length int64 @@ -109,6 +110,9 @@ func (c *Copier) getAttrs(ctx context.Context, bucket, prefix string) ([]ObjectA return nil, Total{}, fmt.Errorf("storage: copier list objects %w", err) } for _, attr := range page.Contents { + if attr.IsEmpty() { + continue + } attrs = append(attrs, attr) length += attr.Length count++