(
target: &path::Path,
source: &path::Path,
patterns: &[S],
)
| 326 | } |
| 327 | |
| 328 | fn copy_files<S>( |
| 329 | target: &path::Path, |
| 330 | source: &path::Path, |
| 331 | patterns: &[S], |
| 332 | ) -> Result<(), FixtureError> |
| 333 | where |
| 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)] |
| 363 | fn symlink_to_file(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> { |
no test coverage detected