s3: fix --s3-versions on individual objects

Before this fix attempting to access an s3 versioned object by name in
a subdirectory of root would not find the object.

This fixes the problem and introduced an integraton test.

See: https://forum.rclone.org/t/s3-versions-cant-retrieve-old-version/36900
This commit is contained in:
Nick Craig-Wood 2023-03-21 12:44:45 +00:00
parent d481aa8613
commit 542677d807
2 changed files with 23 additions and 5 deletions

View file

@ -3119,6 +3119,7 @@ func (f *Fs) getMetaDataListing(ctx context.Context, wantRemote string) (info *s
err = f.list(ctx, listOpt{
bucket: bucket,
directory: bucketPath,
prefix: f.rootDirectory,
recurse: true,
withVersions: f.opt.Versions,
findFile: true,
@ -3524,10 +3525,10 @@ type listOpt struct {
// list lists the objects into the function supplied with the opt
// supplied.
func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error {
if opt.prefix != "" {
opt.prefix += "/"
}
if !opt.findFile {
if opt.prefix != "" {
opt.prefix += "/"
}
if opt.directory != "" {
opt.directory += "/"
}