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

Method IsNonEmptyDirectory

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

Source from the content-addressed store, hash-verified

2469 }
2470
2471 Result<bool> IsNonEmptyDirectory(const S3Path& path) {
2472 ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());
2473
2474 S3Model::ListObjectsV2Request req;
2475 req.SetBucket(ToAwsString(path.bucket));
2476 req.SetPrefix(ToAwsString(path.key) + kSep);
2477 req.SetDelimiter(Aws::String() + kSep);
2478 req.SetMaxKeys(1);
2479 auto outcome = client_lock.Move()->ListObjectsV2(req);
2480 if (outcome.IsSuccess()) {
2481 const S3Model::ListObjectsV2Result& r = outcome.GetResult();
2482 // In some cases, there may be 0 keys but some prefixes
2483 return r.GetKeyCount() > 0 || !r.GetCommonPrefixes().empty();
2484 }
2485 if (IsNotFound(outcome.GetError())) {
2486 return false;
2487 }
2488 return ErrorToStatus(
2489 std::forward_as_tuple("When listing objects under key '", path.key,
2490 "' in bucket '", path.bucket, "': "),
2491 "ListObjectsV2", outcome.GetError());
2492 }
2493
2494 static FileInfo MakeDirectoryInfo(std::string dirname) {
2495 FileInfo dir;

Callers 1

GetFileInfoMethod · 0.80

Calls 7

ToAwsStringFunction · 0.85
StringClass · 0.85
IsNotFoundFunction · 0.85
ErrorToStatusFunction · 0.85
MoveMethod · 0.45
GetResultMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected