From 6163ae7cc79f9296d3f0caff16401ada6cafd750 Mon Sep 17 00:00:00 2001 From: Davide Bizzarri Date: Tue, 13 May 2025 18:35:57 +0200 Subject: [PATCH] fix: b2 versionAt read metadata --- backend/b2/b2.go | 15 +++++++++++++++ backend/b2/b2_internal_test.go | 16 ++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/backend/b2/b2.go b/backend/b2/b2.go index 71c3ccb9b..e54d7a439 100644 --- a/backend/b2/b2.go +++ b/backend/b2/b2.go @@ -1673,6 +1673,21 @@ func (o *Object) getMetaData(ctx context.Context) (info *api.File, err error) { return o.getMetaDataListing(ctx) } } + + // If using versionAt we need to list the find the correct version. + if o.fs.opt.VersionAt.IsSet() { + info, err := o.getMetaDataListing(ctx) + if err != nil { + return nil, err + } + + if info.Action == "hide" { + // Rerturn object not found error if the current version is deleted. + return nil, fs.ErrorObjectNotFound + } + return info, nil + } + _, info, err = o.getOrHead(ctx, "HEAD", nil) return info, err } diff --git a/backend/b2/b2_internal_test.go b/backend/b2/b2_internal_test.go index 168f61233..2579928be 100644 --- a/backend/b2/b2_internal_test.go +++ b/backend/b2/b2_internal_test.go @@ -446,14 +446,14 @@ func (f *Fs) InternalTestVersions(t *testing.T) { t.Run("List", func(t *testing.T) { fstest.CheckListing(t, f, test.want) }) - // b2 NewObject doesn't work with VersionAt - //t.Run("NewObject", func(t *testing.T) { - // gotObj, gotErr := f.NewObject(ctx, fileName) - // assert.Equal(t, test.wantErr, gotErr) - // if gotErr == nil { - // assert.Equal(t, test.wantSize, gotObj.Size()) - // } - //}) + + t.Run("NewObject", func(t *testing.T) { + gotObj, gotErr := f.NewObject(ctx, fileName) + assert.Equal(t, test.wantErr, gotErr) + if gotErr == nil { + assert.Equal(t, test.wantSize, gotObj.Size()) + } + }) }) } })