| 619 | } |
| 620 | |
| 621 | Status FileCache::DeleteFile(const string& file_name) { |
| 622 | // Mark any outstanding descriptor as deleted. Because there may only be one |
| 623 | // descriptor per file name, we can short circuit the search if we find a |
| 624 | // descriptor in the first map. |
| 625 | { |
| 626 | std::lock_guard<simple_spinlock> l(lock_); |
| 627 | bool ignored; |
| 628 | { |
| 629 | auto d = FindDescriptorUnlocked(file_name, FindMode::DONT_CREATE, |
| 630 | &rwf_descs_, &ignored); |
| 631 | if (d) { |
| 632 | if (d->base_.deleted()) { |
| 633 | return Status::NotFound(kAlreadyDeleted, file_name); |
| 634 | } |
| 635 | d->base_.MarkDeleted(); |
| 636 | return Status::OK(); |
| 637 | } |
| 638 | } |
| 639 | { |
| 640 | auto d = FindDescriptorUnlocked(file_name, FindMode::DONT_CREATE, |
| 641 | &raf_descs_, &ignored); |
| 642 | if (d) { |
| 643 | if (d->base_.deleted()) { |
| 644 | return Status::NotFound(kAlreadyDeleted, file_name); |
| 645 | } |
| 646 | d->base_.MarkDeleted(); |
| 647 | return Status::OK(); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | // There are no outstanding descriptors. Delete the file now. |
| 653 | // |
| 654 | // Make sure it's been fully evicted from the cache (perhaps it was opened |
| 655 | // previously?) so that the filesystem can reclaim the file data instantly. |
| 656 | cache_->Erase(file_name); |
| 657 | return env_->DeleteFile(file_name); |
| 658 | } |
| 659 | |
| 660 | void FileCache::Invalidate(const string& file_name) { |
| 661 | // Ensure that there are invalidated descriptors in both maps for this |