From 77429b154e57006d14a81fc018301c598c0038f8 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 4 Jan 2025 10:24:06 +0000 Subject: [PATCH] s3: fix handling of objects with // in #5858 --- backend/s3/s3.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index c26d63a3c..2adcc333a 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -3677,6 +3677,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if opt.Provider == "IDrive" { f.features.SetTier = false } + if opt.Provider == "AWS" { + f.features.DoubleSlash = true + } if opt.DirectoryMarkers { f.features.CanHaveEmptyDirectories = true } @@ -4148,7 +4151,7 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error { opt.prefix += "/" } if !opt.findFile { - if opt.directory != "" { + if opt.directory != "" && (opt.prefix == "" && !bucket.IsAllSlashes(opt.directory) || opt.prefix != "" && !strings.HasSuffix(opt.directory, "/")) { opt.directory += "/" } } @@ -4245,14 +4248,18 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error { } remote = f.opt.Enc.ToStandardPath(remote) if !strings.HasPrefix(remote, opt.prefix) { - fs.Logf(f, "Odd name received %q", remote) + fs.Logf(f, "Odd directory name received %q", remote) continue } remote = remote[len(opt.prefix):] + // Trim one slash off the remote name + remote, _ = strings.CutSuffix(remote, "/") + if remote == "" || bucket.IsAllSlashes(remote) { + remote += "/" + } if opt.addBucket { remote = bucket.Join(opt.bucket, remote) } - remote = strings.TrimSuffix(remote, "/") err = fn(remote, &types.Object{Key: &remote}, nil, true) if err != nil { if err == errEndList {