MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / rename

Method rename

atomic-core/src/output/memory.rs:629–658  ·  view source on GitHub ↗
(&self, from: &str, to: &str)

Source from the content-addressed store, hash-verified

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();

Callers 3

test_rename_fileFunction · 0.45
test_rename_directoryFunction · 0.45
test_rename_not_foundFunction · 0.45

Calls 2

removeMethod · 0.65
insertMethod · 0.45

Tested by 3

test_rename_fileFunction · 0.36
test_rename_directoryFunction · 0.36
test_rename_not_foundFunction · 0.36