pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
  if !from.exists() {
    return Err(crate::Error::GenericError(format!(
      "{:?} does not exist",
      from
    )));
  }
  if !from.is_dir() {
    return Err(crate::Error::GenericError(format!(
      "{:?} is not a Directory",
      from
    )));
  }
  if to.exists() {
    return Err(crate::Error::GenericError(format!(
      "{:?} already exists",
      from
    )));
  }
  let parent = to.parent().expect("No data in parent");
  fs::create_dir_all(parent)?;
  for entry in walkdir::WalkDir::new(from) {
    let entry = entry?;
    debug_assert!(entry.path().starts_with(from));
    let rel_path = entry.path().strip_prefix(from)?;
    let dest_path = to.join(rel_path);
    if entry.file_type().is_symlink() {
      let target = fs::read_link(entry.path())?;
      if entry.path().is_dir() {
        symlink_dir(&target, &dest_path)?;
      } else {
        symlink_file(&target, &dest_path)?;
      }
    } else if entry.file_type().is_dir() {
      fs::create_dir(dest_path)?;
    } else {
      fs::copy(entry.path(), dest_path)?;
    }
  }
  Ok(())
}
/// Recursively copies a directory file from one path to another, creating any
/// parent directories of the destination path as necessary.  Fails if the
/// source path is not a directory or doesn't exist, or if the destination path
/// already exists.
Recursively copies a directory file from one path to another, creating any
parent directories of the destination path as necessary.  Fails if the
source path is not a directory or doesn't exist, or if the destination path
already exists.
Recursively copies a directory file from one path to another creating any parent directories of the destination path as necessary . Fails if the source path is not a directory or doesn ' t exist or if the destination path already exists .
pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
  if !from.exists() {
    return Err(crate::Error::GenericError(format!(
      "{:?} does not exist",
      from
    )));
  }
  if !from.is_dir() {
    return Err(crate::Error::GenericError(format!(
      "{:?} is not a Directory",
      from
    )));
  }
  if to.exists() {
    return Err(crate::Error::GenericError(format!(
      "{:?} already exists",
      from
    )));
  }
  let parent = to.parent().expect("No data in parent");
  fs::create_dir_all(parent)?;
  for entry in walkdir::WalkDir::new(from) {
    let entry = entry?;
    debug_assert!(entry.path().starts_with(from));
    let rel_path = entry.path().strip_prefix(from)?;
    let dest_path = to.join(rel_path);
    if entry.file_type().is_symlink() {
      let target = fs::read_link(entry.path())?;
      if entry.path().is_dir() {
        symlink_dir(&target, &dest_path)?;
      } else {
        symlink_file(&target, &dest_path)?;
      }
    } else if entry.file_type().is_dir() {
      fs::create_dir(dest_path)?;
    } else {
      fs::copy(entry.path(), dest_path)?;
    }
  }
  Ok(())
}
pub fn copy_dir ( from : & Path , to : & Path ) -> crate :: Result < ( ) > { if ! from . exists ( ) { return Err ( crate :: Error :: GenericError ( format ! ( " " from ) ) ) ; } if ! from . is_dir ( ) { return Err ( crate :: Error :: GenericError ( format ! ( " " from ) ) ) ; } if to . exists ( ) { return Err ( crate :: Error :: GenericError ( format ! ( " " from ) ) ) ; } let parent = to . parent ( ) . expect ( " " ) ; fs :: create_dir_all ( parent ) ? ; for entry in walkdir :: WalkDir :: new ( from ) { let entry = entry ? ; debug_assert ! ( entry path ( ) starts_with ( from ) ) ; let rel_path = entry . path ( ) . strip_prefix ( from ) ? ; let dest_path = to . join ( rel_path ) ; if entry . file_type ( ) . is_symlink ( ) { let target = fs :: read_link ( entry . path ( ) ) ? ; if entry . path ( ) . is_dir ( ) { symlink_dir ( & target , & dest_path ) ? ; } else { symlink_file ( & target , & dest_path ) ? ; } } else if entry . file_type ( ) . is_dir ( ) { fs :: create_dir ( dest_path ) ? ; } else { fs :: copy ( entry . path ( ) , dest_path ) ? ; } } Ok ( ( ) ) }
Recursively copies a directory file from one path to another, creating any
parent directories of the destination path as necessary.
Recursively copies a directory file from one path to another creating any parent directories of the destination path as necessary .
from
&Path
to
&Path
from
&Path
to
&Path