mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:16:05 +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
@ -137,6 +137,7 @@ pub enum Stub<'a> {
|
||||
FileWithContent(&'a str, &'a str),
|
||||
FileWithContentToBeTrimmed(&'a str, &'a str),
|
||||
EmptyFile(&'a str),
|
||||
FileWithPermission(&'a str, bool),
|
||||
}
|
||||
|
||||
pub fn file_contents(full_path: impl AsRef<Path>) -> String {
|
||||
|
@ -202,7 +202,8 @@ impl<'a> Playground<'a> {
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let mut path = PathBuf::from(&self.cwd);
|
||||
|
||||
let mut permission_set = false;
|
||||
let mut write_able = true;
|
||||
let (file_name, contents) = match *f {
|
||||
Stub::EmptyFile(name) => (name, "fake data".to_string()),
|
||||
Stub::FileWithContent(name, content) => (name, content.to_string()),
|
||||
@ -215,11 +216,24 @@ impl<'a> Playground<'a> {
|
||||
.collect::<Vec<&str>>()
|
||||
.join(&endl),
|
||||
),
|
||||
Stub::FileWithPermission(name, is_write_able) => {
|
||||
permission_set = true;
|
||||
write_able = is_write_able;
|
||||
(name, "check permission".to_string())
|
||||
}
|
||||
};
|
||||
|
||||
path.push(file_name);
|
||||
|
||||
std::fs::write(path, contents.as_bytes()).expect("can not create file");
|
||||
std::fs::write(&path, contents.as_bytes()).expect("can not create file");
|
||||
if permission_set {
|
||||
let err_perm = "can not set permission";
|
||||
let mut perm = std::fs::metadata(path.clone())
|
||||
.expect(err_perm)
|
||||
.permissions();
|
||||
perm.set_readonly(!write_able);
|
||||
std::fs::set_permissions(path, perm).expect(err_perm);
|
||||
}
|
||||
})
|
||||
.for_each(drop);
|
||||
self.back_to_playground();
|
||||
|
Reference in New Issue
Block a user