Skip to content

Commit

Permalink
fix(s3): unable to copy empty folder (close #4620)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 10, 2023
1 parent 3529023 commit 61101a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions drivers/s3/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (d *S3) Drop(ctx context.Context) error {

func (d *S3) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
if d.ListObjectVersion == "v2" {
return d.listV2(dir.GetPath())
return d.listV2(dir.GetPath(), args)
}
return d.listV1(dir.GetPath())
return d.listV1(dir.GetPath(), args)
}

func (d *S3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
Expand Down
10 changes: 5 additions & 5 deletions drivers/s3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func getPlaceholderName(placeholder string) string {
return placeholder
}

func (d *S3) listV1(prefix string) ([]model.Obj, error) {
func (d *S3) listV1(prefix string, args model.ListArgs) ([]model.Obj, error) {
prefix = getKey(prefix, true)
log.Debugf("list: %s", prefix)
files := make([]model.Obj, 0)
Expand Down Expand Up @@ -97,7 +97,7 @@ func (d *S3) listV1(prefix string) ([]model.Obj, error) {
}
for _, object := range listObjectsResult.Contents {
name := path.Base(*object.Key)
if name == getPlaceholderName(d.Placeholder) || name == d.Placeholder {
if !args.S3ShowPlaceholder && (name == getPlaceholderName(d.Placeholder) || name == d.Placeholder) {
continue
}
file := model.Object{
Expand All @@ -120,7 +120,7 @@ func (d *S3) listV1(prefix string) ([]model.Obj, error) {
return files, nil
}

func (d *S3) listV2(prefix string) ([]model.Obj, error) {
func (d *S3) listV2(prefix string, args model.ListArgs) ([]model.Obj, error) {
prefix = getKey(prefix, true)
files := make([]model.Obj, 0)
var continuationToken, startAfter *string
Expand Down Expand Up @@ -152,7 +152,7 @@ func (d *S3) listV2(prefix string) ([]model.Obj, error) {
continue
}
name := path.Base(*object.Key)
if name == getPlaceholderName(d.Placeholder) || name == d.Placeholder {
if !args.S3ShowPlaceholder && (name == getPlaceholderName(d.Placeholder) || name == d.Placeholder) {
continue
}
file := model.Object{
Expand Down Expand Up @@ -198,7 +198,7 @@ func (d *S3) copyFile(ctx context.Context, src string, dst string) error {
}

func (d *S3) copyDir(ctx context.Context, src string, dst string) error {
objs, err := op.List(ctx, d, src, model.ListArgs{})
objs, err := op.List(ctx, d, src, model.ListArgs{S3ShowPlaceholder: true})
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/model/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type ListArgs struct {
ReqPath string
ReqPath string
S3ShowPlaceholder bool
}

type LinkArgs struct {
Expand Down

0 comments on commit 61101a6

Please sign in to comment.