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 .env
result result
*.log *.log
*.rar
profile.* profile.*
*.out.* *.out.*
/logs /logs

View file

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

20
flake.lock generated
View file

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

View file

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

View file

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