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

storage: do not copy empty file #62

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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
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