mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:45:08 +02:00
Fix: dst error on cp command (#7895)
Fixes #7693 On `cp` commands there were two error which pass error message with invalid detail about source and destination files . there error were for Not exist file and Permission denied . Examples: Before : Copy `source_file_valid` to `destination_invalid_dir` throw this error ; `copy file "/source_file_valid" failed: No such file or directory (os error 2) ` After this PR it will throw this if destination will be invalid : `copying to destination "/destination_invalid_dir" failed: No such file or directory (os error 2) ` it was for Permission denied too . --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4db960c0a6
commit
c130ca1bc6
@ -1,5 +1,8 @@
|
||||
use nu_test_support::fs::file_contents;
|
||||
use nu_test_support::fs::{files_exist_at, AbsoluteFile, Stub::EmptyFile};
|
||||
use nu_test_support::fs::{
|
||||
files_exist_at, AbsoluteFile,
|
||||
Stub::{EmptyFile, FileWithPermission},
|
||||
};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::path::Path;
|
||||
@ -344,3 +347,37 @@ fn copy_ignores_ansi() {
|
||||
assert_eq!(actual.out, "success.txt");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_not_exists_dst() {
|
||||
Playground::setup("cp_test_17", |_dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("valid.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: sandbox.cwd(),
|
||||
"cp valid.txt ~/invalid_dir/invalid_dir1"
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("invalid_dir1") && actual.err.contains("copying to destination")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_with_read_permission() {
|
||||
Playground::setup("cp_test_18", |_dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("valid.txt"),
|
||||
FileWithPermission("invalid_prem.txt", false),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: sandbox.cwd(),
|
||||
"cp valid.txt invalid_prem.txt",
|
||||
);
|
||||
assert!(
|
||||
actual.err.contains("invalid_prem.txt")
|
||||
&& actual.err.contains("copying to destination")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user