From 0ff6d8c31a65877df6abf7dc999839bc0153effa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E6=99=93=E5=A8=81?= Date: Wed, 3 Dec 2025 23:22:56 +0800 Subject: [PATCH] fix: update getVersioningState to signal non-existent buckets with ErrNotFound This change modifies the getVersioningState function to return filer_pb.ErrNotFound when a requested bucket does not exist, allowing callers to handle the situation appropriately, such as auto-creating the bucket in PUT handlers. This improves error handling and clarity in the API's behavior regarding bucket existence. --- weed/s3api/s3api_bucket_config.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/weed/s3api/s3api_bucket_config.go b/weed/s3api/s3api_bucket_config.go index 00449d80a..9bef3d2d3 100644 --- a/weed/s3api/s3api_bucket_config.go +++ b/weed/s3api/s3api_bucket_config.go @@ -516,14 +516,16 @@ func (s3a *S3ApiServer) isVersioningConfigured(bucket string) (bool, error) { // getVersioningState returns the detailed versioning state for a bucket func (s3a *S3ApiServer) getVersioningState(bucket string) (string, error) { - config, errCode := s3a.getBucketConfig(bucket) - if errCode != s3err.ErrNone { - if errCode == s3err.ErrNoSuchBucket { - return "", nil - } - glog.Errorf("getVersioningState: failed to get bucket config for %s: %v", bucket, errCode) - return "", fmt.Errorf("failed to get bucket config: %v", errCode) - } + config, errCode := s3a.getBucketConfig(bucket) + if errCode != s3err.ErrNone { + if errCode == s3err.ErrNoSuchBucket { + // Signal to callers that the bucket does not exist so they can + // decide whether to auto-create it (e.g., in PUT handlers). + return "", filer_pb.ErrNotFound + } + glog.Errorf("getVersioningState: failed to get bucket config for %s: %v", bucket, errCode) + return "", fmt.Errorf("failed to get bucket config: %v", errCode) + } // If object lock is enabled, versioning must be enabled regardless of explicit setting if config.ObjectLockConfig != nil {