From 13d97ee1cc51543a803ba66c15eaa983daad0032 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 9 Aug 2017 15:35:13 -0700 Subject: [PATCH] Correct behavior of cp -r with non-existent dest --- src/cp/cp.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 674e60acc..98f47fe51 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -726,7 +726,12 @@ fn copy_directory(root: &Path, target: &Target, options: &Options) -> CopyResult } let root_path = Path::new(&root).canonicalize()?; - let root_parent = root_path.parent(); + + let root_parent = if target.exists() { + root_path.parent() + } else { + Some(root_path.as_path()) + }; for path in WalkDir::new(root) { let path = or_continue!(or_continue!(path).path().canonicalize());