| 1541 | } |
| 1542 | |
| 1543 | Status GcsFileSystem::CreateDir(const string& dirname) { |
| 1544 | string bucket, object; |
| 1545 | TF_RETURN_IF_ERROR(ParseGcsPath(dirname, true, &bucket, &object)); |
| 1546 | if (object.empty()) { |
| 1547 | bool is_bucket; |
| 1548 | TF_RETURN_IF_ERROR(BucketExists(bucket, &is_bucket)); |
| 1549 | return is_bucket ? Status::OK() |
| 1550 | : errors::NotFound("The specified bucket ", dirname, |
| 1551 | " was not found."); |
| 1552 | } |
| 1553 | |
| 1554 | const string dirname_with_slash = MaybeAppendSlash(dirname); |
| 1555 | |
| 1556 | if (FileExists(dirname_with_slash).ok()) { |
| 1557 | return errors::AlreadyExists(dirname); |
| 1558 | } |
| 1559 | |
| 1560 | // Create a zero-length directory marker object. |
| 1561 | std::unique_ptr<WritableFile> file; |
| 1562 | TF_RETURN_IF_ERROR(NewWritableFile(dirname_with_slash, &file)); |
| 1563 | TF_RETURN_IF_ERROR(file->Close()); |
| 1564 | return Status::OK(); |
| 1565 | } |
| 1566 | |
| 1567 | // Checks that the directory is empty (i.e no objects with this prefix exist). |
| 1568 | // Deletes the GCS directory marker if it exists. |