mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +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),
|
Some(password) => Archive::with_password(archive_path, password),
|
||||||
None => Archive::new(archive_path),
|
None => Archive::new(archive_path),
|
||||||
};
|
};
|
||||||
archive.open_for_listing().expect("cannot open archive").map(|item| {
|
match archive.open_for_listing() {
|
||||||
let item = item?;
|
Ok(iter) => iter.map(|item| {
|
||||||
let is_dir = item.is_directory();
|
let item = item?;
|
||||||
let path = item.filename;
|
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 {
|
pub fn no_compression() -> Error {
|
||||||
|
@ -187,7 +187,7 @@ pub fn list_archive(
|
|||||||
if let Err(e) = reader {
|
if let Err(e) = reader {
|
||||||
return vec![Err(Error::IoError {reason:e.to_string()})].into_iter();
|
return vec![Err(Error::IoError {reason:e.to_string()})].into_iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
let reader = reader.unwrap();
|
let reader = reader.unwrap();
|
||||||
|
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user