Glob paths can fail. Communicates the error if it happens. thanks (jonathandturner)

This commit is contained in:
Andrés N. Robalino 2019-08-01 16:55:49 -05:00
parent 375f311331
commit 1bc1bb6111
2 changed files with 17 additions and 9 deletions

View File

@ -45,7 +45,15 @@ pub fn rm(args: CommandArgs) -> Result<OutputStream, ShellError> {
file => full_path.push(file), file => full_path.push(file),
} }
for entry in glob(&full_path.to_string_lossy()).expect("Failed to read glob pattern") { let entries = glob(&full_path.to_string_lossy());
if entries.is_err() {
return Err(ShellError::string("Invalid pattern."));
}
let entries = entries.unwrap();
for entry in entries {
match entry { match entry {
Ok(path) => { Ok(path) => {
if path.is_dir() { if path.is_dir() {