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

Method IsEmptyDirectory

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

If this method is called after HEAD on "bucket/key" already returned a 404, can pass the given outcome to spare a spurious HEAD call.

Source from the content-addressed store, hash-verified

2423 // If this method is called after HEAD on "bucket/key" already returned a 404,
2424 // can pass the given outcome to spare a spurious HEAD call.
2425 Result<bool> IsEmptyDirectory(
2426 const std::string& bucket, const std::string& key,
2427 const S3Model::HeadObjectOutcome* previous_outcome = nullptr) {
2428 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2429
2430 if (previous_outcome) {
2431 // Fetch the backend from the previous error
2432 if (GetOrSetBackend(previous_outcome->GetError()) != S3Backend::Minio) {
2433 // HEAD already returned a 404, nothing more to do
2434 return false;
2435 }
2436 }
2437
2438 // We come here in one of two situations:
2439 // - we don't know the backend and there is no previous outcome
2440 // - the backend is Minio
2441 S3Model::HeadObjectRequest req;
2442 req.SetBucket(ToAwsString(bucket));
2443 if (backend_ && *backend_ == S3Backend::Minio) {
2444 // Minio wants a slash at the end, Amazon doesn't
2445 req.SetKey(ToAwsString(key) + kSep);
2446 } else {
2447 req.SetKey(ToAwsString(key));
2448 }
2449
2450 auto outcome = client_lock.Move()->HeadObject(req);
2451 if (outcome.IsSuccess()) {
2452 return true;
2453 }
2454 if (!backend_) {
2455 if (GetOrSetBackend(outcome.GetError()) == S3Backend::Minio) {
2456 // Try again with separator-terminated key (see above)
2457 return IsEmptyDirectory(bucket, key);
2458 }
2459 }
2460 if (IsNotFound(outcome.GetError())) {
2461 return false;
2462 }
2463 return ErrorToStatus(std::forward_as_tuple("When reading information for key '", key,
2464 "' in bucket '", bucket, "': "),
2465 "HeadObject", outcome.GetError());
2466 }
2467
2468 Result<bool> IsEmptyDirectory(
2469 const S3Path& path, const S3Model::HeadObjectOutcome* previous_outcome = nullptr) {

Callers 1

CreateDirMethod · 0.80

Calls 4

ToAwsStringFunction · 0.85
IsNotFoundFunction · 0.85
ErrorToStatusFunction · 0.85
MoveMethod · 0.45

Tested by

no test coverage detected