MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Stat

Method Stat

tensorflow/core/platform/s3/s3_file_system.cc:444–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

442}
443
444Status S3FileSystem::Stat(const string& fname, FileStatistics* stats) {
445 string bucket, object;
446 TF_RETURN_IF_ERROR(ParseS3Path(fname, true, &bucket, &object));
447
448 if (object.empty()) {
449 Aws::S3::Model::HeadBucketRequest headBucketRequest;
450 headBucketRequest.WithBucket(bucket.c_str());
451 auto headBucketOutcome = this->GetS3Client()->HeadBucket(headBucketRequest);
452 if (!headBucketOutcome.IsSuccess()) {
453 return errors::Unknown(headBucketOutcome.GetError().GetExceptionName(),
454 ": ", headBucketOutcome.GetError().GetMessage());
455 }
456 stats->length = 0;
457 stats->is_directory = 1;
458 return Status::OK();
459 }
460
461 bool found = false;
462
463 Aws::S3::Model::HeadObjectRequest headObjectRequest;
464 headObjectRequest.WithBucket(bucket.c_str()).WithKey(object.c_str());
465 headObjectRequest.SetResponseStreamFactory(
466 []() { return Aws::New<Aws::StringStream>(kS3FileSystemAllocationTag); });
467 auto headObjectOutcome = this->GetS3Client()->HeadObject(headObjectRequest);
468 if (headObjectOutcome.IsSuccess()) {
469 stats->length = headObjectOutcome.GetResult().GetContentLength();
470 stats->is_directory = 0;
471 stats->mtime_nsec =
472 headObjectOutcome.GetResult().GetLastModified().Millis() * 1e6;
473 found = true;
474 }
475 string prefix = object;
476 if (prefix.back() != '/') {
477 prefix.push_back('/');
478 }
479 Aws::S3::Model::ListObjectsRequest listObjectsRequest;
480 listObjectsRequest.WithBucket(bucket.c_str())
481 .WithPrefix(prefix.c_str())
482 .WithMaxKeys(1);
483 listObjectsRequest.SetResponseStreamFactory(
484 []() { return Aws::New<Aws::StringStream>(kS3FileSystemAllocationTag); });
485 auto listObjectsOutcome =
486 this->GetS3Client()->ListObjects(listObjectsRequest);
487 if (listObjectsOutcome.IsSuccess()) {
488 if (listObjectsOutcome.GetResult().GetContents().size() > 0) {
489 stats->length = 0;
490 stats->is_directory = 1;
491 found = true;
492 }
493 }
494 if (!found) {
495 return errors::NotFound("Object ", fname, " does not exist");
496 }
497 return Status::OK();
498}
499
500Status S3FileSystem::GetMatchingPaths(const string& pattern,
501 std::vector<string>* results) {

Callers 3

FileExistsMethod · 0.95
GetFileSizeMethod · 0.95
TEST_FFunction · 0.45

Calls 11

GetS3ClientMethod · 0.95
ParseS3PathFunction · 0.85
NotFoundFunction · 0.85
c_strMethod · 0.80
GetErrorMethod · 0.80
UnknownClass · 0.50
emptyMethod · 0.45
GetResultMethod · 0.45
backMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.36