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

Function plan_switch_collisions

atomic-cli/src/commands/git/shim.rs:1625–1674  ·  view source on GitHub ↗
(
    root: &Path,
    current_paths: &BTreeSet<String>,
    target_paths: &BTreeSet<String>,
)

Source from the content-addressed store, hash-verified

1623}
1624
1625fn plan_switch_collisions(
1626 root: &Path,
1627 current_paths: &BTreeSet<String>,
1628 target_paths: &BTreeSet<String>,
1629) -> Result<(), String> {
1630 for path in target_paths.difference(current_paths) {
1631 let relative = Path::new(path);
1632 let mut parent = relative.parent();
1633 while let Some(component) = parent {
1634 if component.as_os_str().is_empty() {
1635 break;
1636 }
1637 match fs::symlink_metadata(root.join(component)) {
1638 Ok(metadata) if !metadata.file_type().is_dir() => {
1639 return Err(format!(
1640 "cannot switch: target path '{path}' has non-directory parent '{}'",
1641 component.display()
1642 ));
1643 }
1644 Ok(_) => {}
1645 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
1646 Err(error) => {
1647 return Err(format!(
1648 "cannot inspect target path parent '{}': {error}",
1649 component.display()
1650 ));
1651 }
1652 }
1653 parent = component.parent();
1654 }
1655
1656 match fs::symlink_metadata(root.join(relative)) {
1657 Ok(metadata) if metadata.file_type().is_dir() => {
1658 return Err(format!(
1659 "cannot switch: target file path '{path}' is occupied by a directory"
1660 ));
1661 }
1662 Ok(_) => {
1663 return Err(format!(
1664 "cannot switch: target tracked path '{path}' is occupied in the working tree"
1665 ));
1666 }
1667 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
1668 Err(error) => {
1669 return Err(format!("cannot inspect target path '{path}': {error}"));
1670 }
1671 }
1672 }
1673 Ok(())
1674}
1675
1676fn checkpoint_matches_snapshot(checkpoint: &ShimCheckpoint, snapshot: &ShimSnapshot) -> bool {
1677 checkpoint.view == snapshot.view

Calls 4

parentMethod · 0.80
is_dirMethod · 0.80
is_emptyMethod · 0.45
kindMethod · 0.45