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

Method DeleteDir

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

Source from the content-addressed store, hash-verified

542}
543
544Status S3FileSystem::DeleteDir(const string& dirname) {
545 string bucket, object;
546 TF_RETURN_IF_ERROR(ParseS3Path(dirname, false, &bucket, &object));
547
548 string prefix = object;
549 if (prefix.back() != '/') {
550 prefix.push_back('/');
551 }
552 Aws::S3::Model::ListObjectsRequest listObjectsRequest;
553 listObjectsRequest.WithBucket(bucket.c_str())
554 .WithPrefix(prefix.c_str())
555 .WithMaxKeys(2);
556 listObjectsRequest.SetResponseStreamFactory(
557 []() { return Aws::New<Aws::StringStream>(kS3FileSystemAllocationTag); });
558 auto listObjectsOutcome =
559 this->GetS3Client()->ListObjects(listObjectsRequest);
560 if (listObjectsOutcome.IsSuccess()) {
561 auto contents = listObjectsOutcome.GetResult().GetContents();
562 if (contents.size() > 1 ||
563 (contents.size() == 1 && contents[0].GetKey() != prefix.c_str())) {
564 return errors::FailedPrecondition("Cannot delete a non-empty directory.");
565 }
566 if (contents.size() == 1 && contents[0].GetKey() == prefix.c_str()) {
567 string filename = dirname;
568 if (filename.back() != '/') {
569 filename.push_back('/');
570 }
571 return DeleteFile(filename);
572 }
573 }
574 return Status::OK();
575}
576
577Status S3FileSystem::GetFileSize(const string& fname, uint64* file_size) {
578 FileStatistics stats;

Callers 1

TEST_FFunction · 0.45

Calls 9

GetS3ClientMethod · 0.95
ParseS3PathFunction · 0.85
FailedPreconditionFunction · 0.85
c_strMethod · 0.80
backMethod · 0.45
push_backMethod · 0.45
GetResultMethod · 0.45
sizeMethod · 0.45
GetKeyMethod · 0.45

Tested by 1

TEST_FFunction · 0.36