switch rar implementation again, as rar-stream has dissapeared from the face of the earth

This commit is contained in:
Robin Appelman 2026-09-15 15:55:20 +02:00
commit da4f7ff4b8
5 changed files with 29 additions and 23 deletions

1
.gitignore vendored
View file

@ -3,6 +3,7 @@ target
.env
result
*.log
*.rar
profile.*
*.out.*
/logs

View file

@ -2,7 +2,7 @@
name = "logsmash"
version = "0.2.2"
edition = "2021"
rust-version = "1.88.0"
rust-version = "1.97.1"
license = "GPL-3.0-only"
[dependencies]
@ -22,7 +22,6 @@ logsmash-data = { path = "./data", version = "0.1.0" }
main_error = "0.1.2"
matchit = "0.9.0"
osc94 = "0.1.1"
rar-stream = "5.7.1"
ratatui = { version = "0.30.0", features = ["unstable-rendered-line-info"] }
rayon = "1.11.0"
regex = "1.12.2"
@ -39,6 +38,7 @@ time = { version = "0.3.44", features = [
"serde-well-known"
] }
tinystr = { version = "0.8.2", features = ["serde"] }
unrar-rs = "0.10.5"
xz2 = "0.1.7"
zip = "8.1.0"

20
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"crane": {
"locked": {
"lastModified": 1780099841,
"narHash": "sha256-EVZd2RsbpreRUDSi9rBwPY+ZxoyMaiEBbZxxhljbaS4=",
"lastModified": 1788465171,
"narHash": "sha256-Y1/TTVXjYXGF068IThQH9fPSZ0SIE74PABlUxnWTUH0=",
"owner": "ipetkov",
"repo": "crane",
"rev": "0532eb17955225173906d671fb36306bdeb1e2dc",
"rev": "eb35abda9f232cc6610b1d1e3200d15c49b7ac54",
"type": "github"
},
"original": {
@ -44,11 +44,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1786478312,
"narHash": "sha256-ocOwon+Sa+6Ep9x9INI4mjuXlcRerD61Rnx6eyPtf08=",
"lastModified": 1789480598,
"narHash": "sha256-G1jy1kz2dLJCkVjjY2PnCXEL1B2iqMlSfz01YFCBY+c=",
"ref": "refs/heads/main",
"rev": "d0e2d12f13bf2dc43611f63e62ad375c04c6df12",
"revCount": 75,
"rev": "c1e026caf1750f226a20dab66594dc1ef3a34ec4",
"revCount": 77,
"type": "git",
"url": "https://codeberg.org/icewind/mill-scale.git"
},
@ -88,11 +88,11 @@
]
},
"locked": {
"lastModified": 1780197589,
"narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
"lastModified": 1789457514,
"narHash": "sha256-Aggle++fTyAifBy+QBPxjM+obO5iepKW/8MDxQtgGvI=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
"rev": "89e99bf0778a8f2cd18c9360c3f19c1ee47fc739",
"type": "github"
},
"original": {

View file

@ -28,7 +28,7 @@ pub enum ReadError {
#[error(transparent)]
SevenZip(#[from] sevenz_rust2::Error),
#[error(transparent)]
Rar(#[from] rar_stream::error::RarError),
Rar(#[from] unrar_rs::RarError),
#[error("archive contains no files")]
NoFiles,
#[error("log file contained non-utf8 characters: {0:#}")]

View file

@ -1,24 +1,24 @@
use crate::error::ReadError;
use crate::logfile::archive::{Archive, ArchiveEntry};
use rar_stream::MemoryArchive;
use crate::logfile::archive::{read_to_vec, Archive, ArchiveEntry};
use std::borrow::Cow;
use std::fs::read;
use std::cell::RefCell;
use std::fs::File;
use unrar_rs::RarArchive as UnrarArchive;
pub struct RarArchive {
archive: MemoryArchive,
archive: RefCell<UnrarArchive>,
}
impl RarArchive {
pub fn new(path: &str) -> Result<Self, ReadError> {
let data = read(path)?;
Ok(RarArchive {
archive: MemoryArchive::from_vec(data)?,
archive: RefCell::new(UnrarArchive::open(File::open(path)?)?),
})
}
}
pub struct RarEntry<'a> {
archive: &'a MemoryArchive,
archive: &'a RefCell<UnrarArchive>,
index: usize,
name: String,
}
@ -29,7 +29,9 @@ impl ArchiveEntry for RarEntry<'_> {
}
fn extract(self) -> Result<Vec<u8>, ReadError> {
Ok(self.archive.extract(self.index)?)
let mut archive = self.archive.borrow_mut();
let entry = archive.by_index(self.index)?;
read_to_vec(entry.size().unwrap_or_default() as usize, entry)
}
}
@ -38,7 +40,8 @@ impl Archive for RarArchive {
fn entries(&mut self) -> impl Iterator<Item = Self::Entry<'_>> {
self.archive
.entries_iter()
.borrow()
.entries()
.enumerate()
.filter(|(_, entry)| !entry.is_directory)
.map(|(index, entry)| RarEntry {
@ -46,5 +49,7 @@ impl Archive for RarArchive {
index,
name: entry.name,
})
.collect::<Vec<_>>()
.into_iter()
}
}