| 1491 | } |
| 1492 | |
| 1493 | Status GcsFileSystem::Stat(const string& fname, FileStatistics* stat) { |
| 1494 | if (!stat) { |
| 1495 | return errors::Internal("'stat' cannot be nullptr."); |
| 1496 | } |
| 1497 | string bucket, object; |
| 1498 | TF_RETURN_IF_ERROR(ParseGcsPath(fname, true, &bucket, &object)); |
| 1499 | if (object.empty()) { |
| 1500 | bool is_bucket; |
| 1501 | TF_RETURN_IF_ERROR(BucketExists(bucket, &is_bucket)); |
| 1502 | if (is_bucket) { |
| 1503 | *stat = DIRECTORY_STAT; |
| 1504 | return Status::OK(); |
| 1505 | } |
| 1506 | return errors::NotFound("The specified bucket ", fname, " was not found."); |
| 1507 | } |
| 1508 | |
| 1509 | GcsFileStat gcs_stat; |
| 1510 | const Status status = StatForObject(fname, bucket, object, &gcs_stat); |
| 1511 | if (status.ok()) { |
| 1512 | *stat = gcs_stat.base; |
| 1513 | return Status::OK(); |
| 1514 | } |
| 1515 | if (status.code() != errors::Code::NOT_FOUND) { |
| 1516 | return status; |
| 1517 | } |
| 1518 | bool is_folder; |
| 1519 | TF_RETURN_IF_ERROR(FolderExists(fname, &is_folder)); |
| 1520 | if (is_folder) { |
| 1521 | *stat = DIRECTORY_STAT; |
| 1522 | return Status::OK(); |
| 1523 | } |
| 1524 | return errors::NotFound("The specified path ", fname, " was not found."); |
| 1525 | } |
| 1526 | |
| 1527 | Status GcsFileSystem::DeleteFile(const string& fname) { |
| 1528 | string bucket, object; |