More informative error messages when "rm" fails (#2109)
* add a nicer error message * small fix to message and remove log
This commit is contained in:
parent
bbc5a28fe9
commit
8ea2307815
|
@ -15,6 +15,7 @@ use crate::utils::FileStructure;
|
||||||
use rustyline::completion::FilenameCompleter;
|
use rustyline::completion::FilenameCompleter;
|
||||||
use rustyline::hint::{Hinter, HistoryHinter};
|
use rustyline::hint::{Hinter, HistoryHinter};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -587,25 +588,27 @@ impl Shell for FilesystemShell {
|
||||||
.map(|val| val.is_true())
|
.map(|val| val.is_true())
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
result = if _trash.item || (rm_always_trash && !_permanent.item) {
|
result = if _trash.item || (rm_always_trash && !_permanent.item) {
|
||||||
trash::remove(&f).map_err(|_| f.to_string_lossy())
|
trash::remove(&f).map_err(|e: trash::Error| {
|
||||||
|
Error::new(ErrorKind::Other, format!("{:?}", e))
|
||||||
|
})
|
||||||
} else if metadata.is_file() {
|
} else if metadata.is_file() {
|
||||||
std::fs::remove_file(&f).map_err(|_| f.to_string_lossy())
|
std::fs::remove_file(&f)
|
||||||
} else {
|
} else {
|
||||||
std::fs::remove_dir_all(&f).map_err(|_| f.to_string_lossy())
|
std::fs::remove_dir_all(&f)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "trash-support"))]
|
#[cfg(not(feature = "trash-support"))]
|
||||||
{
|
{
|
||||||
result = if metadata.is_file() {
|
result = if metadata.is_file() {
|
||||||
std::fs::remove_file(&f).map_err(|_| f.to_string_lossy())
|
std::fs::remove_file(&f)
|
||||||
} else {
|
} else {
|
||||||
std::fs::remove_dir_all(&f).map_err(|_| f.to_string_lossy())
|
std::fs::remove_dir_all(&f)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
let msg = format!("Could not delete {:}", e);
|
let msg = format!("Could not delete because: {:}", e);
|
||||||
Err(ShellError::labeled_error(msg, e, tag))
|
Err(ShellError::labeled_error(msg, e.to_string(), tag))
|
||||||
} else {
|
} else {
|
||||||
let val = format!("deleted {:}", f.to_string_lossy()).into();
|
let val = format!("deleted {:}", f.to_string_lossy()).into();
|
||||||
Ok(ReturnSuccess::Value(val))
|
Ok(ReturnSuccess::Value(val))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user