s3: fix --s3-versions flag ignored by cleanup-hidden when GetBucketVersioning fails

When a user has --s3-versions set but lacks the s3:GetBucketVersioning
permission, GetBucketVersioning returns an error and isVersioned() caches
the result as false. This caused CleanUpHidden (backend cleanup-hidden) to
silently exit with "bucket is not versioned so not removing old versions",
ignoring the user's explicit --s3-versions flag.

Fix this by trusting the explicit --s3-versions flag in purge(), bypassing
the GetBucketVersioning check when the user has explicitly declared the
bucket is versioned.
This commit is contained in:
Chris
2026-04-03 17:12:42 +02:00
committed by Nick Craig-Wood
parent d15f1142ef
commit 40b064993e

View File

@@ -3783,7 +3783,9 @@ func (f *Fs) purge(ctx context.Context, dir string, oldOnly bool) error {
if bucket == "" {
return errors.New("can't purge from root")
}
versioned := f.isVersioned(ctx)
// If the user explicitly set --s3-versions, trust that the bucket is
// versioned even if GetBucketVersioning fails (e.g. missing permission).
versioned := f.opt.Versions || f.isVersioned(ctx)
if !versioned && oldOnly {
fs.Infof(f, "bucket is not versioned so not removing old versions")
return nil