| 627 | } |
| 628 | |
| 629 | fn rename(&self, from: &str, to: &str) -> Result<(), Self::Error> { |
| 630 | let mut files = self.files.borrow_mut(); |
| 631 | |
| 632 | // Get the entry |
| 633 | let entry = files.remove(from).ok_or_else(|| MemoryError::NotFound { |
| 634 | path: from.to_string(), |
| 635 | })?; |
| 636 | |
| 637 | // Insert at new location |
| 638 | files.insert(to.to_string(), entry); |
| 639 | |
| 640 | // If it's a directory, also rename all children |
| 641 | let from_prefix = format!("{}/", from); |
| 642 | let to_prefix = format!("{}/", to); |
| 643 | |
| 644 | let children: Vec<_> = files |
| 645 | .keys() |
| 646 | .filter(|p| p.starts_with(&from_prefix)) |
| 647 | .cloned() |
| 648 | .collect(); |
| 649 | |
| 650 | for child in children { |
| 651 | if let Some(entry) = files.remove(&child) { |
| 652 | let new_path = child.replacen(&from_prefix, &to_prefix, 1); |
| 653 | files.insert(new_path, entry); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | Ok(()) |
| 658 | } |
| 659 | |
| 660 | fn set_permissions(&self, path: &str, permissions: u16) -> Result<(), Self::Error> { |
| 661 | let mut files = self.files.borrow_mut(); |