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

Method CreateBucket

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

Create a bucket. Successful if bucket already exists.

Source from the content-addressed store, hash-verified

2320
2321 // Create a bucket. Successful if bucket already exists.
2322 Status CreateBucket(const std::string& bucket) {
2323 // Check bucket exists first.
2324 {
2325 S3Model::HeadBucketRequest req;
2326 req.SetBucket(ToAwsString(bucket));
2327 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2328 auto outcome = client_lock.Move()->HeadBucket(req);
2329
2330 if (outcome.IsSuccess()) {
2331 return Status::OK();
2332 } else if (!IsNotFound(outcome.GetError())) {
2333 return ErrorToStatus(
2334 std::forward_as_tuple("When creating bucket '", bucket, "': "), "HeadBucket",
2335 outcome.GetError());
2336 }
2337
2338 if (!options().allow_bucket_creation) {
2339 return Status::IOError(
2340 "Bucket '", bucket, "' not found. ",
2341 "To create buckets, enable the allow_bucket_creation option.");
2342 }
2343 }
2344
2345 S3Model::CreateBucketConfiguration config;
2346 S3Model::CreateBucketRequest req;
2347 auto _region = region();
2348 // AWS S3 treats the us-east-1 differently than other regions
2349 // https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html
2350 if (_region != "us-east-1") {
2351 config.SetLocationConstraint(
2352 S3Model::BucketLocationConstraintMapper::GetBucketLocationConstraintForName(
2353 ToAwsString(_region)));
2354 }
2355 req.SetBucket(ToAwsString(bucket));
2356 req.SetCreateBucketConfiguration(config);
2357
2358 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2359 auto outcome = client_lock.Move()->CreateBucket(req);
2360 if (!outcome.IsSuccess() && !IsAlreadyExists(outcome.GetError())) {
2361 return ErrorToStatus(std::forward_as_tuple("When creating bucket '", bucket, "': "),
2362 "CreateBucket", outcome.GetError());
2363 }
2364 return Status::OK();
2365 }
2366
2367 // Create a directory-like object with empty contents. Successful if already exists.
2368 Status CreateEmptyDir(const std::string& bucket, std::string_view key_view) {

Callers 6

TEST_FFunction · 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

TEST_FFunction · 0.64
SetUpMethod · 0.64