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:
ttyS3 2024-09-06 16:00:27 +00:00 committed by João Marcos
parent f8f1439ec5
commit c3e37e22d1
2 changed files with 7 additions and 16 deletions

View File

@ -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 {

View File

@ -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}")