mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
refactor(rar): simplify list_archive logic and remove UnrarError
Simplify the list_archive function by combining archive creation and listing steps. Remove the UnrarError variant from the Error enum as it's no longer used.
This commit is contained in:
parent
f8f1439ec5
commit
c3e37e22d1
@ -54,21 +54,15 @@ pub fn list_archive(
|
||||
None => Archive::new(archive_path),
|
||||
};
|
||||
|
||||
let result = match archive.open_for_listing() {
|
||||
Ok(iter) => iter
|
||||
.map(|item| {
|
||||
let item = item?;
|
||||
let is_dir = item.is_directory();
|
||||
let path = item.filename;
|
||||
let archive = archive.open_for_listing()?;
|
||||
|
||||
Ok(FileInArchive { path, is_dir })
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
Err(e) => return Err(Error::UnrarError { reason: e.to_string() }),
|
||||
};
|
||||
Ok(archive.map(|item| {
|
||||
let item = item?;
|
||||
let is_dir = item.is_directory();
|
||||
let path = item.filename;
|
||||
|
||||
Ok(result)
|
||||
Ok(FileInArchive { path, is_dir })
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn no_compression() -> Error {
|
||||
|
@ -41,8 +41,6 @@ pub enum Error {
|
||||
UnsupportedFormat { reason: String },
|
||||
/// Invalid password provided
|
||||
InvalidPassword { reason: String },
|
||||
/// UnrarError From unrar::error::UnrarError
|
||||
UnrarError { reason: String },
|
||||
}
|
||||
|
||||
/// Alias to std's Result with ouch's Error
|
||||
@ -153,7 +151,6 @@ impl fmt::Display for Error {
|
||||
FinalError::with_title("Recognised but unsupported format").detail(reason.clone())
|
||||
}
|
||||
Error::InvalidPassword { reason } => FinalError::with_title("Invalid password").detail(reason.clone()),
|
||||
Error::UnrarError { reason } => FinalError::with_title("Unrar error").detail(reason.clone()),
|
||||
};
|
||||
|
||||
write!(f, "{err}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user