mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
fix(archive): handle errors for unsupported formats
Handle errors for unsupported formats in RAR and 7z archives by returning appropriate error messages.
This commit is contained in:
parent
bafbd83bd7
commit
7e830d9f53
@ -53,13 +53,16 @@ pub fn list_archive(
|
||||
Some(password) => Archive::with_password(archive_path, password),
|
||||
None => Archive::new(archive_path),
|
||||
};
|
||||
archive.open_for_listing().expect("cannot open archive").map(|item| {
|
||||
let item = item?;
|
||||
let is_dir = item.is_directory();
|
||||
let path = item.filename;
|
||||
match archive.open_for_listing() {
|
||||
Ok(iter) => iter.map(|item| {
|
||||
let item = item?;
|
||||
let is_dir = item.is_directory();
|
||||
let path = item.filename;
|
||||
|
||||
Ok(FileInArchive { path, is_dir })
|
||||
})
|
||||
Ok(FileInArchive { path, is_dir })
|
||||
}).collect::<Vec<_>>().into_iter(),
|
||||
Err(e) => vec![Err(Error::UnsupportedFormat {reason:e.to_string()})].into_iter(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_compression() -> Error {
|
||||
|
@ -187,7 +187,7 @@ pub fn list_archive(
|
||||
if let Err(e) = reader {
|
||||
return vec![Err(Error::IoError {reason:e.to_string()})].into_iter();
|
||||
}
|
||||
|
||||
|
||||
let reader = reader.unwrap();
|
||||
|
||||
let mut files = Vec::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user