@@ -33,48 +33,52 @@ func (c *Client) makeBucket(ctx context.Context, bucketName string, opts MakeBuc
33
33
return err
34
34
}
35
35
36
- err = c .doMakeBucket (ctx , bucketName , opts . Region , opts . ObjectLocking )
36
+ err = c .doMakeBucket (ctx , bucketName , opts )
37
37
if err != nil && (opts .Region == "" || opts .Region == "us-east-1" ) {
38
38
if resp , ok := err .(ErrorResponse ); ok && resp .Code == "AuthorizationHeaderMalformed" && resp .Region != "" {
39
- err = c .doMakeBucket (ctx , bucketName , resp .Region , opts .ObjectLocking )
39
+ opts .Region = resp .Region
40
+ err = c .doMakeBucket (ctx , bucketName , opts )
40
41
}
41
42
}
42
43
return err
43
44
}
44
45
45
- func (c * Client ) doMakeBucket (ctx context.Context , bucketName , location string , objectLockEnabled bool ) (err error ) {
46
+ func (c * Client ) doMakeBucket (ctx context.Context , bucketName string , opts MakeBucketOptions ) (err error ) {
46
47
defer func () {
47
48
// Save the location into cache on a successful makeBucket response.
48
49
if err == nil {
49
- c .bucketLocCache .Set (bucketName , location )
50
+ c .bucketLocCache .Set (bucketName , opts . Region )
50
51
}
51
52
}()
52
53
53
54
// If location is empty, treat is a default region 'us-east-1'.
54
- if location == "" {
55
- location = "us-east-1"
55
+ if opts . Region == "" {
56
+ opts . Region = "us-east-1"
56
57
// For custom region clients, default
57
58
// to custom region instead not 'us-east-1'.
58
59
if c .region != "" {
59
- location = c .region
60
+ opts . Region = c .region
60
61
}
61
62
}
62
63
// PUT bucket request metadata.
63
64
reqMetadata := requestMetadata {
64
65
bucketName : bucketName ,
65
- bucketLocation : location ,
66
+ bucketLocation : opts . Region ,
66
67
}
67
68
68
- if objectLockEnabled {
69
- headers := make (http. Header )
69
+ headers := make (http. Header )
70
+ if opts . ObjectLocking {
70
71
headers .Add ("x-amz-bucket-object-lock-enabled" , "true" )
71
- reqMetadata .customHeader = headers
72
72
}
73
+ if opts .ForceCreate {
74
+ headers .Add ("x-minio-force-create" , "true" )
75
+ }
76
+ reqMetadata .customHeader = headers
73
77
74
78
// If location is not 'us-east-1' create bucket location config.
75
- if location != "us-east-1" && location != "" {
79
+ if opts . Region != "us-east-1" && opts . Region != "" {
76
80
createBucketConfig := createBucketConfiguration {}
77
- createBucketConfig .Location = location
81
+ createBucketConfig .Location = opts . Region
78
82
var createBucketConfigBytes []byte
79
83
createBucketConfigBytes , err = xml .Marshal (createBucketConfig )
80
84
if err != nil {
@@ -109,6 +113,9 @@ type MakeBucketOptions struct {
109
113
Region string
110
114
// Enable object locking
111
115
ObjectLocking bool
116
+
117
+ // ForceCreate - this is a MinIO specific extension.
118
+ ForceCreate bool
112
119
}
113
120
114
121
// MakeBucket creates a new bucket with bucketName with a context to control cancellations and timeouts.
0 commit comments