MCPcopy Create free account
hub / github.com/assert-rs/assert_fs / copy_files

Function copy_files

src/fixture/tools.rs:328–360  ·  view source on GitHub ↗
(
    target: &path::Path,
    source: &path::Path,
    patterns: &[S],
)

Source from the content-addressed store, hash-verified

326}
327
328fn copy_files<S>(
329 target: &path::Path,
330 source: &path::Path,
331 patterns: &[S],
332) -> Result<(), FixtureError>
333where
334 S: AsRef<str>,
335{
336 // `walkdir`, on Windows, seems to convert "." into "" which then fails.
337 let source = source
338 .canonicalize()
339 .chain(FixtureError::new(FixtureKind::Walk))?;
340 for entry in globwalk::GlobWalkerBuilder::from_patterns(&source, patterns)
341 .follow_links(true)
342 .build()
343 .chain(FixtureError::new(FixtureKind::Walk))?
344 {
345 let entry = entry.chain(FixtureError::new(FixtureKind::Walk))?;
346 let rel = entry
347 .path()
348 .strip_prefix(&source)
349 .expect("entries to be under `source`");
350 let target_path = target.join(rel);
351 if entry.file_type().is_dir() {
352 fs::create_dir_all(target_path).chain(FixtureError::new(FixtureKind::CreateDir))?;
353 } else if entry.file_type().is_file() {
354 fs::create_dir_all(target_path.parent().expect("at least `target` exists"))
355 .chain(FixtureError::new(FixtureKind::CreateDir))?;
356 fs::copy(entry.path(), target_path).chain(FixtureError::new(FixtureKind::CopyFile))?;
357 }
358 }
359 Ok(())
360}
361
362#[cfg(windows)]
363fn symlink_to_file(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> {

Callers 1

copy_fromMethod · 0.85

Calls 3

create_dir_allFunction · 0.85
chainMethod · 0.80
pathMethod · 0.45

Tested by

no test coverage detected