From de9c4a3611cca65d4adc0876d5a2e8e0f194520b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 3 Mar 2023 10:45:29 +0000 Subject: [PATCH] s3: use bucket.Join instead of path.Join to preserve paths Before this change, path.Join would remove the trailing / from objects which had them. The simplified bucket.Join does not. --- backend/s3/s3.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index 58ab02abc..edf68edd1 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -2534,7 +2534,7 @@ func parsePath(path string) (root string) { // split returns bucket and bucketPath from the rootRelativePath // relative to f.root func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) { - bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath)) + bucketName, bucketPath = bucket.Split(bucket.Join(f.root, rootRelativePath)) return f.opt.Enc.FromStandardName(bucketName), f.opt.Enc.FromStandardPath(bucketPath) } @@ -3589,7 +3589,7 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error { } remote = remote[len(opt.prefix):] if opt.addBucket { - remote = path.Join(opt.bucket, remote) + remote = bucket.Join(opt.bucket, remote) } remote = strings.TrimSuffix(remote, "/") err = fn(remote, &s3.Object{Key: &remote}, nil, true) @@ -3618,7 +3618,7 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error { remote = remote[len(opt.prefix):] isDirectory := remote == "" || strings.HasSuffix(remote, "/") if opt.addBucket { - remote = path.Join(opt.bucket, remote) + remote = bucket.Join(opt.bucket, remote) } // is this a directory marker? if isDirectory && object.Size != nil && *object.Size == 0 { @@ -3911,7 +3911,7 @@ func (f *Fs) copy(ctx context.Context, req *s3.CopyObjectInput, dstBucket, dstPa req.Bucket = &dstBucket req.ACL = stringPointerOrNil(f.opt.ACL) req.Key = &dstPath - source := pathEscape(path.Join(srcBucket, srcPath)) + source := pathEscape(bucket.Join(srcBucket, srcPath)) if src.versionID != nil { source += fmt.Sprintf("?versionId=%s", *src.versionID) }