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

Function replace_worktree

atomic-repository/src/repository/snapshot_split.rs:836–888  ·  view source on GitHub ↗
(source: &Path, destination: &Path)

Source from the content-addressed store, hash-verified

834}
835
836fn replace_worktree(source: &Path, destination: &Path) -> Result<(), SplitSnapshotError> {
837 for entry in std::fs::read_dir(destination).map_err(RepositoryError::Io)? {
838 let entry = entry.map_err(RepositoryError::Io)?;
839 if entry.file_name() != ".atomic" {
840 remove_path(&entry.path())?;
841 }
842 }
843 for entry in walkdir::WalkDir::new(source).follow_links(false) {
844 let entry =
845 entry.map_err(|error| RepositoryError::Io(std::io::Error::other(error.to_string())))?;
846 let relative = entry.path().strip_prefix(source).map_err(|error| {
847 RepositoryError::InvalidOperation {
848 message: error.to_string(),
849 }
850 })?;
851 if relative.as_os_str().is_empty()
852 || matches!(relative.components().next(), Some(Component::Normal(first)) if first == ".atomic" || first == ".git")
853 {
854 continue;
855 }
856 let target = destination.join(relative);
857 let metadata = std::fs::symlink_metadata(entry.path()).map_err(RepositoryError::Io)?;
858 if metadata.file_type().is_dir() {
859 std::fs::create_dir_all(&target).map_err(RepositoryError::Io)?;
860 } else if metadata.file_type().is_symlink() {
861 let bytes = crate::content_filter::read_working_bytes(entry.path())
862 .map_err(RepositoryError::Io)?;
863 create_symlink(&target, &bytes)?;
864 } else if metadata.file_type().is_file() {
865 if let Some(parent) = target.parent() {
866 std::fs::create_dir_all(parent).map_err(RepositoryError::Io)?;
867 }
868 std::fs::copy(entry.path(), &target).map_err(RepositoryError::Io)?;
869 } else {
870 return Err(SplitSnapshotError::Refused(
871 SnapshotSplitRefusal::UnsupportedUnit {
872 path: relative.display().to_string(),
873 reason: "unsupported filesystem entry kind".to_string(),
874 },
875 ));
876 }
877 #[cfg(unix)]
878 if !metadata.file_type().is_symlink() {
879 use std::os::unix::fs::PermissionsExt;
880 std::fs::set_permissions(
881 &target,
882 std::fs::Permissions::from_mode(metadata.permissions().mode()),
883 )
884 .map_err(RepositoryError::Io)?;
885 }
886 }
887 Ok(())
888}
889
890fn refresh_scratch_git_index(
891 source_root: &Path,

Callers 1

split_snapshotMethod · 0.85

Calls 13

remove_pathFunction · 0.85
read_working_bytesFunction · 0.85
set_permissionsFunction · 0.85
is_dirMethod · 0.80
parentMethod · 0.80
displayMethod · 0.80
create_symlinkFunction · 0.70
file_nameMethod · 0.45
pathMethod · 0.45
is_emptyMethod · 0.45
is_fileMethod · 0.45
modeMethod · 0.45

Tested by

no test coverage detected