Skip to content

Commit

Permalink
Simplify the adjust_canonicalization function
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jun 19, 2020
1 parent 173a79a commit d0c3410
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,15 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
}

#[cfg(target_os = "windows")]
fn adjust_canonicalization<'a, P: AsRef<Path>>(p: P) -> Cow<'a, Path> {
fn adjust_canonicalization<'a, P: 'a + AsRef<Path> + Into<PathBuf>>(p: P) -> Cow<'a, Path> {
// In some cases, \\? can be missing some Windows path.
// Add it at the beginning
const VERBATIM_PREFIX: &str = r#"\\?\"#;
let p = p.as_ref().display().to_string();
if p.starts_with(VERBATIM_PREFIX) {
Path::new(&p[VERBATIM_PREFIX.len()..].to_string()).to_path_buf().into()
let p_str = p.as_ref().display().to_string();
if p_str.starts_with(VERBATIM_PREFIX) {
Cow::Owned(p.into())
} else {
Path::new(&p).to_path_buf().into()
Path::new(VERBATIM_PREFIX).join(p).into()
}
}

Expand Down

0 comments on commit d0c3410

Please sign in to comment.