Delete a change from disk and the cache. # Arguments `hash` - The hash of the change to delete # Returns `true` if the change was deleted, `false` if it didn't exist. # Errors Returns an error if the file exists but cannot be deleted. # Example ```rust,ignore if store.delete_change(&hash)? { println!("Change deleted"); } else { println!("Change didn't exist"); } ```
(&self, hash: &Hash)
| 482 | /// } |
| 483 | /// ``` |
| 484 | pub fn delete_change(&self, hash: &Hash) -> ChangeStoreResult<bool> { |
| 485 | // Remove from cache |
| 486 | if let Ok(mut cache) = self.cache.write() { |
| 487 | cache.remove(hash); |
| 488 | } |
| 489 | |
| 490 | // Remove from disk |
| 491 | let path = self.change_path(hash); |
| 492 | |
| 493 | if !path.exists() { |
| 494 | return Ok(false); |
| 495 | } |
| 496 | |
| 497 | fs::remove_file(&path)?; |
| 498 | |
| 499 | // Try to remove the parent directory if it's empty |
| 500 | // This is best-effort; we don't care if it fails |
| 501 | if let Some(parent) = path.parent() { |
| 502 | let _ = fs::remove_dir(parent); |
| 503 | } |
| 504 | |
| 505 | log::debug!( |
| 506 | "Deleted change {} from {}", |
| 507 | hash.to_base32(), |
| 508 | path.display() |
| 509 | ); |
| 510 | |
| 511 | Ok(true) |
| 512 | } |
| 513 | |
| 514 | /// Iterate over all change hashes stored on disk. |
| 515 | /// |