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)
| 606 | /// Clone a working tree from `src` to `dest`, one file at a time, reflinking |
| 607 | /// where possible. Skips the `.atomic/` graph directory. |
| 608 | fn 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 | /// |