| 1579 | } |
| 1580 | |
| 1581 | fn plan_switch_collisions( |
| 1582 | root: &Path, |
| 1583 | current_paths: &BTreeSet<String>, |
| 1584 | target_paths: &BTreeSet<String>, |
| 1585 | ) -> Result<(), String> { |
| 1586 | for path in target_paths.difference(current_paths) { |
| 1587 | let relative = Path::new(path); |
| 1588 | let mut parent = relative.parent(); |
| 1589 | while let Some(component) = parent { |
| 1590 | if component.as_os_str().is_empty() { |
| 1591 | break; |
| 1592 | } |
| 1593 | match fs::symlink_metadata(root.join(component)) { |
| 1594 | Ok(metadata) if !metadata.file_type().is_dir() => { |
| 1595 | return Err(format!( |
| 1596 | "cannot switch: target path '{path}' has non-directory parent '{}'", |
| 1597 | component.display() |
| 1598 | )); |
| 1599 | } |
| 1600 | Ok(_) => {} |
| 1601 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} |
| 1602 | Err(error) => { |
| 1603 | return Err(format!( |
| 1604 | "cannot inspect target path parent '{}': {error}", |
| 1605 | component.display() |
| 1606 | )); |
| 1607 | } |
| 1608 | } |
| 1609 | parent = component.parent(); |
| 1610 | } |
| 1611 | |
| 1612 | match fs::symlink_metadata(root.join(relative)) { |
| 1613 | Ok(metadata) if metadata.file_type().is_dir() => { |
| 1614 | return Err(format!( |
| 1615 | "cannot switch: target file path '{path}' is occupied by a directory" |
| 1616 | )); |
| 1617 | } |
| 1618 | Ok(_) => { |
| 1619 | return Err(format!( |
| 1620 | "cannot switch: target tracked path '{path}' is occupied in the working tree" |
| 1621 | )); |
| 1622 | } |
| 1623 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} |
| 1624 | Err(error) => { |
| 1625 | return Err(format!("cannot inspect target path '{path}': {error}")); |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | Ok(()) |
| 1630 | } |
| 1631 | |
| 1632 | fn checkpoint_matches_snapshot(checkpoint: &ShimCheckpoint, snapshot: &ShimSnapshot) -> bool { |
| 1633 | checkpoint.view == snapshot.view |