From f17278a121a2b391bc33d6587934b52900e71955 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Sat, 3 Sep 2016 03:07:17 -0700 Subject: [PATCH] Remove redundant directory level --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9afd56e..c0075dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,9 @@ fn send_to_graveyard(source: &str, graveyard: &Path) -> std::io::Result<()> { } }; + let parent: &Path = dest.parent().expect("Trying to delete / ?"); + fs::create_dir_all(parent).expect("Failed to create grave path"); + // Try a simple rename, which will only work within the same mount point. // Trying to rename across filesystems will throw errno 18. if let Ok(_) = fs::rename(&fullpath, &dest) { @@ -62,21 +65,18 @@ fn send_to_graveyard(source: &str, graveyard: &Path) -> std::io::Result<()> { // If that didn't work, then copy and rm. if fullpath.is_dir() { - fs::create_dir_all(&dest).expect("Failed to create grave path"); for entry in WalkDir::new(source) { let entry = entry.expect("Failed to open file in source dir"); let path = entry.path(); if path.is_dir() { - println!("{}", dest.join(path).display()); - fs::create_dir(dest.join(path)).expect("Copy dir failed"); + println!("{}", parent.join(path).display()); + fs::create_dir(parent.join(path)).expect("Copy dir failed"); } else { - fs::copy(path, dest.join(path)).expect("Copy file failed"); + fs::copy(path, parent.join(path)).expect("Copy file failed"); } } fs::remove_dir_all(&fullpath).expect("Failed to remove source dir"); } else { - let parent: &Path = dest.parent().expect("Trying to delete / ?"); - fs::create_dir_all(parent).expect("Failed to create grave path"); try!(fs::copy(&fullpath, &dest)); try!(fs::remove_file(source)); }