| 394 | } |
| 395 | |
| 396 | Status S3FileSystem::GetChildren(const string& dir, |
| 397 | std::vector<string>* result) { |
| 398 | string bucket, prefix; |
| 399 | TF_RETURN_IF_ERROR(ParseS3Path(dir, false, &bucket, &prefix)); |
| 400 | |
| 401 | if (prefix.back() != '/') { |
| 402 | prefix.push_back('/'); |
| 403 | } |
| 404 | |
| 405 | Aws::S3::Model::ListObjectsRequest listObjectsRequest; |
| 406 | listObjectsRequest.WithBucket(bucket.c_str()) |
| 407 | .WithPrefix(prefix.c_str()) |
| 408 | .WithMaxKeys(kS3GetChildrenMaxKeys) |
| 409 | .WithDelimiter("/"); |
| 410 | listObjectsRequest.SetResponseStreamFactory( |
| 411 | []() { return Aws::New<Aws::StringStream>(kS3FileSystemAllocationTag); }); |
| 412 | |
| 413 | Aws::S3::Model::ListObjectsResult listObjectsResult; |
| 414 | do { |
| 415 | auto listObjectsOutcome = |
| 416 | this->GetS3Client()->ListObjects(listObjectsRequest); |
| 417 | if (!listObjectsOutcome.IsSuccess()) { |
| 418 | return errors::Unknown(listObjectsOutcome.GetError().GetExceptionName(), |
| 419 | ": ", listObjectsOutcome.GetError().GetMessage()); |
| 420 | } |
| 421 | |
| 422 | listObjectsResult = listObjectsOutcome.GetResult(); |
| 423 | for (const auto& object : listObjectsResult.GetCommonPrefixes()) { |
| 424 | Aws::String s = object.GetPrefix(); |
| 425 | s.erase(s.length() - 1); |
| 426 | Aws::String entry = s.substr(strlen(prefix.c_str())); |
| 427 | if (entry.length() > 0) { |
| 428 | result->push_back(entry.c_str()); |
| 429 | } |
| 430 | } |
| 431 | for (const auto& object : listObjectsResult.GetContents()) { |
| 432 | Aws::String s = object.GetKey(); |
| 433 | Aws::String entry = s.substr(strlen(prefix.c_str())); |
| 434 | if (entry.length() > 0) { |
| 435 | result->push_back(entry.c_str()); |
| 436 | } |
| 437 | } |
| 438 | listObjectsRequest.SetMarker(listObjectsResult.GetNextMarker()); |
| 439 | } while (listObjectsResult.GetIsTruncated()); |
| 440 | |
| 441 | return Status::OK(); |
| 442 | } |
| 443 | |
| 444 | Status S3FileSystem::Stat(const string& fname, FileStatistics* stats) { |
| 445 | string bucket, object; |