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

Function provision_working_tree

atomic-repository/src/repository/sandbox.rs:608–655  ·  view source on GitHub ↗

Clone a working tree from `src` to `dest`, one file at a time, reflinking where possible. Skips the `.atomic/` graph directory.

(src: &Path, dest: &Path)

Source from the content-addressed store, hash-verified

606/// Clone a working tree from `src` to `dest`, one file at a time, reflinking
607/// where possible. Skips the `.atomic/` graph directory.
608fn provision_working_tree(src: &Path, dest: &Path) -> Result<usize, RepositoryError> {
609 use walkdir::WalkDir;
610
611 let mut count = 0usize;
612 std::fs::create_dir_all(dest)?;
613
614 for entry in WalkDir::new(src).into_iter().filter_entry(|e| {
615 // Never descend into the canonical graph — it is shared, not cloned.
616 if e.file_name() == DOT_DIR {
617 return false;
618 }
619 // Never descend into a nested sandbox (a dir holding its own pointer).
620 if e.file_type().is_dir() && e.path().join(SANDBOX_POINTER).is_file() {
621 return false;
622 }
623 true
624 }) {
625 let entry = entry.map_err(std::io::Error::from)?;
626 let rel = match entry.path().strip_prefix(src) {
627 Ok(r) => r,
628 Err(_) => continue,
629 };
630 if rel.as_os_str().is_empty() {
631 continue;
632 }
633 let target = dest.join(rel);
634
635 let ft = entry.file_type();
636 if ft.is_dir() {
637 std::fs::create_dir_all(&target)?;
638 } else if ft.is_file() {
639 if let Some(parent) = target.parent() {
640 std::fs::create_dir_all(parent)?;
641 }
642 // Single cross-platform path: reflink (CoW) where the filesystem
643 // supports it, plain copy where it does not.
644 reflink_copy::reflink_or_copy(entry.path(), &target)?;
645 count += 1;
646 } else if ft.is_symlink() {
647 if let Some(parent) = target.parent() {
648 std::fs::create_dir_all(parent)?;
649 }
650 let _ = recreate_symlink(entry.path(), &target);
651 }
652 }
653
654 Ok(count)
655}
656
657/// Recreate a symlink found at `src` into `dest`, preserving its target.
658///

Calls 8

recreate_symlinkFunction · 0.85
is_dirMethod · 0.80
parentMethod · 0.80
into_iterMethod · 0.45
file_nameMethod · 0.45
is_fileMethod · 0.45
pathMethod · 0.45
is_emptyMethod · 0.45