]> source.dussan.org Git - gitea.git/commitdiff
Adjust minio new sequence, now it will check whether bucket exist first and then...
authorLunny Xiao <xiaolunwen@gmail.com>
Sat, 12 Aug 2023 08:03:54 +0000 (16:03 +0800)
committerGitHub <noreply@github.com>
Sat, 12 Aug 2023 08:03:54 +0000 (08:03 +0000)
For some reason, the permission of the client_id and secret may cannot
create bucket, so now we will check whether bucket does exist first and
then try to create a bucket if it doesn't exist.

Try to fix #25984

Co-authored-by: silverwind <me@silverwind.io>
modules/storage/minio.go

index e7c315ae44d0a1b947cde5b96c8e4b2ec1686b27..f50f341022c616a429180e03bc19d75556aa092d 100644 (file)
@@ -90,12 +90,16 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
                return nil, convertMinioErr(err)
        }
 
-       if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{
-               Region: config.Location,
-       }); err != nil {
-               // Check to see if we already own this bucket (which happens if you run this twice)
-               exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket)
-               if !exists || errBucketExists != nil {
+       // Check to see if we already own this bucket
+       exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket)
+       if errBucketExists != nil {
+               return nil, convertMinioErr(err)
+       }
+
+       if !exists {
+               if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{
+                       Region: config.Location,
+               }); err != nil {
                        return nil, convertMinioErr(err)
                }
        }