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

Function provision_working_tree

atomic-repository/src/repository/sandbox.rs:363–410  ·  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

361/// Clone a working tree from `src` to `dest`, one file at a time, reflinking
362/// where possible. Skips the `.atomic/` graph directory.
363fn provision_working_tree(src: &Path, dest: &Path) -> Result<usize, RepositoryError> {
364 use walkdir::WalkDir;
365
366 let mut count = 0usize;
367 std::fs::create_dir_all(dest)?;
368
369 for entry in WalkDir::new(src).into_iter().filter_entry(|e| {
370 // Never descend into the canonical graph — it is shared, not cloned.
371 if e.file_name() == DOT_DIR {
372 return false;
373 }
374 // Never descend into a nested sandbox (a dir holding its own pointer).
375 if e.file_type().is_dir() && e.path().join(SANDBOX_POINTER).is_file() {
376 return false;
377 }
378 true
379 }) {
380 let entry = entry.map_err(std::io::Error::from)?;
381 let rel = match entry.path().strip_prefix(src) {
382 Ok(r) => r,
383 Err(_) => continue,
384 };
385 if rel.as_os_str().is_empty() {
386 continue;
387 }
388 let target = dest.join(rel);
389
390 let ft = entry.file_type();
391 if ft.is_dir() {
392 std::fs::create_dir_all(&target)?;
393 } else if ft.is_file() {
394 if let Some(parent) = target.parent() {
395 std::fs::create_dir_all(parent)?;
396 }
397 // Single cross-platform path: reflink (CoW) where the filesystem
398 // supports it, plain copy where it does not.
399 reflink_copy::reflink_or_copy(entry.path(), &target)?;
400 count += 1;
401 } else if ft.is_symlink() {
402 if let Some(parent) = target.parent() {
403 std::fs::create_dir_all(parent)?;
404 }
405 let _ = recreate_symlink(entry.path(), &target);
406 }
407 }
408
409 Ok(count)
410}
411
412/// Recreate a symlink found at `src` into `dest`, preserving its target.
413///

Calls 8

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