Skip to content

Commit e525ae7

Browse files
committed
s3: fix handling of objects with // in #5858
1 parent a08b180 commit e525ae7

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

backend/s3/s3.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
36823682
if opt.Provider == "IDrive" {
36833683
f.features.SetTier = false
36843684
}
3685+
if opt.Provider == "AWS" {
3686+
f.features.DoubleSlash = true
3687+
}
36853688
if opt.DirectoryMarkers {
36863689
f.features.CanHaveEmptyDirectories = true
36873690
}
@@ -4153,7 +4156,7 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error {
41534156
opt.prefix += "/"
41544157
}
41554158
if !opt.findFile {
4156-
if opt.directory != "" {
4159+
if opt.directory != "" && !bucket.IsAllSlashes(opt.directory) {
41574160
opt.directory += "/"
41584161
}
41594162
}
@@ -4250,14 +4253,18 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error {
42504253
}
42514254
remote = f.opt.Enc.ToStandardPath(remote)
42524255
if !strings.HasPrefix(remote, opt.prefix) {
4253-
fs.Logf(f, "Odd name received %q", remote)
4256+
fs.Logf(f, "Odd directory name received %q", remote)
42544257
continue
42554258
}
42564259
remote = remote[len(opt.prefix):]
4260+
// Trim one slash off the remote name
4261+
remote, _ = strings.CutSuffix(remote, "/")
4262+
if remote == "" || bucket.IsAllSlashes(remote) {
4263+
remote += "/"
4264+
}
42574265
if opt.addBucket {
42584266
remote = bucket.Join(opt.bucket, remote)
42594267
}
4260-
remote = strings.TrimSuffix(remote, "/")
42614268
err = fn(remote, &types.Object{Key: &remote}, nil, true)
42624269
if err != nil {
42634270
if err == errEndList {

0 commit comments

Comments
 (0)