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

Commit

Permalink
storage: do not copy empty file (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuan <[email protected]>
  • Loading branch information
huanghaoyuanhhy authored Sep 26, 2023
1 parent 3c176a5 commit 699203d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions storage/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++
Expand Down

0 comments on commit 699203d

Please sign in to comment.