MCPcopy Create free account
hub / github.com/apache/arrow / CreateBucket

Method CreateBucket

cpp/src/arrow/filesystem/s3fs.cc:2263–2306  ·  view source on GitHub ↗

Create a bucket. Successful if bucket already exists.

Source from the content-addressed store, hash-verified

2261
2262 // Create a bucket. Successful if bucket already exists.
2263 Status CreateBucket(const std::string& bucket) {
2264 // Check bucket exists first.
2265 {
2266 S3Model::HeadBucketRequest req;
2267 req.SetBucket(ToAwsString(bucket));
2268 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2269 auto outcome = client_lock.Move()->HeadBucket(req);
2270
2271 if (outcome.IsSuccess()) {
2272 return Status::OK();
2273 } else if (!IsNotFound(outcome.GetError())) {
2274 return ErrorToStatus(
2275 std::forward_as_tuple("When creating bucket '", bucket, "': "), "HeadBucket",
2276 outcome.GetError());
2277 }
2278
2279 if (!options().allow_bucket_creation) {
2280 return Status::IOError(
2281 "Bucket '", bucket, "' not found. ",
2282 "To create buckets, enable the allow_bucket_creation option.");
2283 }
2284 }
2285
2286 S3Model::CreateBucketConfiguration config;
2287 S3Model::CreateBucketRequest req;
2288 auto _region = region();
2289 // AWS S3 treats the us-east-1 differently than other regions
2290 // https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html
2291 if (_region != "us-east-1") {
2292 config.SetLocationConstraint(
2293 S3Model::BucketLocationConstraintMapper::GetBucketLocationConstraintForName(
2294 ToAwsString(_region)));
2295 }
2296 req.SetBucket(ToAwsString(bucket));
2297 req.SetCreateBucketConfiguration(config);
2298
2299 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2300 auto outcome = client_lock.Move()->CreateBucket(req);
2301 if (!outcome.IsSuccess() && !IsAlreadyExists(outcome.GetError())) {
2302 return ErrorToStatus(std::forward_as_tuple("When creating bucket '", bucket, "': "),
2303 "CreateBucket", outcome.GetError());
2304 }
2305 return Status::OK();
2306 }
2307
2308 // Create a directory-like object with empty contents. Successful if already exists.
2309 Status CreateEmptyDir(const std::string& bucket, std::string_view key_view) {

Callers 6

SetUpMethod · 0.80
SetUpMethod · 0.80
CreateDirMethod · 0.80
MakeBucketMethod · 0.80
CreateDirMethod · 0.80

Calls 8

ToAwsStringFunction · 0.85
IsNotFoundFunction · 0.85
ErrorToStatusFunction · 0.85
optionsFunction · 0.85
IOErrorFunction · 0.85
IsAlreadyExistsFunction · 0.70
OKFunction · 0.50
MoveMethod · 0.45

Tested by 2

SetUpMethod · 0.64
SetUpMethod · 0.64