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