From ed86b1fbe83ab5c5667ad31ab62d17ead569f8e6 Mon Sep 17 00:00:00 2001 From: George Tsomlektsis Date: Fri, 7 Feb 2020 18:24:01 +0200 Subject: [PATCH] Fixed mv not moving files on Windows. (#1342) Move files correctly in windows. --- src/shell/filesystem_shell.rs | 16 +++++++++++++++ tests/commands/mv.rs | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/shell/filesystem_shell.rs b/src/shell/filesystem_shell.rs index e6782a9335..d8903f86c0 100644 --- a/src/shell/filesystem_shell.rs +++ b/src/shell/filesystem_shell.rs @@ -720,6 +720,22 @@ impl Shell for FilesystemShell { } Ok(o) => o, } + } else if src.is_file() { + match std::fs::copy(src, dst) { + Err(e) => { + return Err(ShellError::labeled_error( + format!( + "Moving file {:?} to {:?} aborted. {:}", + src, + dst, + e.to_string(), + ), + e.to_string(), + name_tag, + )); + } + Ok(_o) => (), + } } } diff --git a/tests/commands/mv.rs b/tests/commands/mv.rs index 32e9efd75f..a997bb68d5 100644 --- a/tests/commands/mv.rs +++ b/tests/commands/mv.rs @@ -96,6 +96,7 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() assert!(!original_dir.exists()); assert!(expected.exists()); + assert!(files_exist_at(vec!["jonathan.txt"], expected)) }) } @@ -180,3 +181,40 @@ fn moves_using_a_glob() { )); }) } + +#[test] +fn moves_a_directory_with_files() { + Playground::setup("mv_test_9", |dirs, sandbox| { + sandbox + .mkdir("vehicles/car") + .mkdir("vehicles/bicycle") + .with_files(vec![ + EmptyFile("vehicles/car/car1.txt"), + EmptyFile("vehicles/car/car2.txt"), + ]) + .with_files(vec![ + EmptyFile("vehicles/bicycle/bicycle1.txt"), + EmptyFile("vehicles/bicycle/bicycle2.txt"), + ]); + + let original_dir = dirs.test().join("vehicles"); + let expected_dir = dirs.test().join("expected"); + + nu!( + cwd: dirs.test(), + "mv vehicles expected" + ); + + assert!(!original_dir.exists()); + assert!(expected_dir.exists()); + assert!(files_exist_at( + vec![ + "car/car1.txt", + "car/car2.txt", + "bicycle/bicycle1.txt", + "bicycle/bicycle2.txt" + ], + expected_dir + )); + }) +}