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

Function provision_working_tree

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

339/// Clone a working tree from `src` to `dest`, one file at a time, reflinking
340/// where possible. Skips the `.atomic/` graph directory.
341fn provision_working_tree(src: &Path, dest: &Path) -> Result<usize, RepositoryError> {
342 use walkdir::WalkDir;
343
344 let mut count = 0usize;
345 std::fs::create_dir_all(dest)?;
346
347 for entry in WalkDir::new(src).into_iter().filter_entry(|e| {
348 // Never descend into the canonical graph — it is shared, not cloned.
349 if e.file_name() == DOT_DIR {
350 return false;
351 }
352 // Never descend into a nested sandbox (a dir holding its own pointer).
353 if e.file_type().is_dir() && e.path().join(SANDBOX_POINTER).is_file() {
354 return false;
355 }
356 true
357 }) {
358 let entry = entry.map_err(std::io::Error::from)?;
359 let rel = match entry.path().strip_prefix(src) {
360 Ok(r) => r,
361 Err(_) => continue,
362 };
363 if rel.as_os_str().is_empty() {
364 continue;
365 }
366 let target = dest.join(rel);
367
368 let ft = entry.file_type();
369 if ft.is_dir() {
370 std::fs::create_dir_all(&target)?;
371 } else if ft.is_file() {
372 if let Some(parent) = target.parent() {
373 std::fs::create_dir_all(parent)?;
374 }
375 // Single cross-platform path: reflink (CoW) where the filesystem
376 // supports it, plain copy where it does not.
377 reflink_copy::reflink_or_copy(entry.path(), &target)?;
378 count += 1;
379 } else if ft.is_symlink() {
380 if let Some(parent) = target.parent() {
381 std::fs::create_dir_all(parent)?;
382 }
383 let _ = recreate_symlink(entry.path(), &target);
384 }
385 }
386
387 Ok(count)
388}
389
390/// Recreate a symlink found at `src` into `dest`, preserving its target.
391///

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