Checks that the directory is empty (i.e no objects with this prefix exist). Deletes the GCS directory marker if it exists.
| 1567 | // Checks that the directory is empty (i.e no objects with this prefix exist). |
| 1568 | // Deletes the GCS directory marker if it exists. |
| 1569 | Status 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 | |
| 1589 | Status GcsFileSystem::GetFileSize(const string& fname, uint64* file_size) { |
| 1590 | if (!file_size) { |