mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +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
271ac722ba
commit
259f854fc2
@ -54,21 +54,15 @@ pub fn list_archive(
|
|||||||
None => Archive::new(archive_path),
|
None => Archive::new(archive_path),
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = match archive.open_for_listing() {
|
let archive = 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(archive.map(|item| {
|
||||||
})
|
let item = item?;
|
||||||
.collect::<Vec<_>>()
|
let is_dir = item.is_directory();
|
||||||
.into_iter(),
|
let path = item.filename;
|
||||||
Err(e) => return Err(Error::UnrarError { reason: e.to_string() }),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(FileInArchive { path, is_dir })
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn no_compression() -> Error {
|
pub fn no_compression() -> Error {
|
||||||
|
@ -41,8 +41,6 @@ pub enum Error {
|
|||||||
UnsupportedFormat { reason: String },
|
UnsupportedFormat { reason: String },
|
||||||
/// Invalid password provided
|
/// Invalid password provided
|
||||||
InvalidPassword { reason: String },
|
InvalidPassword { reason: String },
|
||||||
/// UnrarError From unrar::error::UnrarError
|
|
||||||
UnrarError { reason: String },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias to std's Result with ouch's Error
|
/// 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())
|
FinalError::with_title("Recognised but unsupported format").detail(reason.clone())
|
||||||
}
|
}
|
||||||
Error::InvalidPassword { reason } => FinalError::with_title("Invalid password").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}")
|
write!(f, "{err}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user