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

Method DeleteDir

tensorflow/core/platform/cloud/gcs_file_system.cc:1569–1587  ·  view source on GitHub ↗

Checks that the directory is empty (i.e no objects with this prefix exist). Deletes the GCS directory marker if it exists.

Source from the content-addressed store, hash-verified

1567// Checks that the directory is empty (i.e no objects with this prefix exist).
1568// Deletes the GCS directory marker if it exists.
1569Status GcsFileSystem::DeleteDir(const string& dirname) {
1570 std::vector<string> children;
1571 // A directory is considered empty either if there are no matching objects
1572 // with the corresponding name prefix or if there is exactly one matching
1573 // object and it is the directory marker. Therefore we need to retrieve
1574 // at most two children for the prefix to detect if a directory is empty.
1575 TF_RETURN_IF_ERROR(
1576 GetChildrenBounded(dirname, 2, &children, true /* recursively */,
1577 true /* include_self_directory_marker */));
1578
1579 if (children.size() > 1 || (children.size() == 1 && !children[0].empty())) {
1580 return errors::FailedPrecondition("Cannot delete a non-empty directory.");
1581 }
1582 if (children.size() == 1 && children[0].empty()) {
1583 // This is the directory marker object. Delete it.
1584 return DeleteFile(MaybeAppendSlash(dirname));
1585 }
1586 return Status::OK();
1587}
1588
1589Status GcsFileSystem::GetFileSize(const string& fname, uint64* file_size) {
1590 if (!file_size) {

Callers 1

TESTFunction · 0.45

Calls 4

FailedPreconditionFunction · 0.85
MaybeAppendSlashFunction · 0.85
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 1

TESTFunction · 0.36