Allow cp to overwrite existing files (#1339)

This commit is contained in:
Ishan Bhanuka 2020-02-05 12:24:05 +05:30 committed by GitHub
parent 7a0bc6bc46
commit 427bde83f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -252,7 +252,7 @@ impl Shell for FilesystemShell {
if entry.is_file() {
let strategy = |(source_file, _depth_level)| {
if destination.exists() {
if destination.is_dir() {
let mut new_dst = dunce::canonicalize(destination.clone())?;
if let Some(name) = entry.file_name() {
new_dst.push(name);

View File

@ -165,3 +165,22 @@ fn copies_using_a_glob() {
));
});
}
#[test]
fn copies_same_file_twice() {
Playground::setup("cp_test_8", |dirs, _| {
nu!(
cwd: dirs.root(),
"cp \"{}\" cp_test_8/sample.ini",
dirs.formats().join("sample.ini")
);
nu!(
cwd: dirs.root(),
"cp \"{}\" cp_test_8/sample.ini",
dirs.formats().join("sample.ini")
);
assert!(dirs.test().join("sample.ini").exists());
});
}