Fixed mv not moving files on Windows. (#1342)

Move files correctly in windows.
This commit is contained in:
George Tsomlektsis 2020-02-07 18:24:01 +02:00 committed by GitHub
parent 44a114111e
commit ed86b1fbe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View File

@ -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) => (),
}
}
}

View File

@ -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
));
})
}