From da4f7ff4b8d3612335ee1123d27b9d26bc626d2e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Sep 2026 15:55:20 +0200 Subject: [PATCH] switch rar implementation again, as rar-stream has dissapeared from the face of the earth --- .gitignore | 3 ++- Cargo.toml | 4 ++-- flake.lock | 20 ++++++++++---------- src/error.rs | 2 +- src/logfile/archive/rar.rs | 23 ++++++++++++++--------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 720e953..156c839 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target .env result *.log +*.rar profile.* *.out.* -/logs \ No newline at end of file +/logs diff --git a/Cargo.toml b/Cargo.toml index a4784b1..379a4a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/flake.lock b/flake.lock index 8ca05d8..f82028b 100644 --- a/flake.lock +++ b/flake.lock @@ -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": { diff --git a/src/error.rs b/src/error.rs index 66b0b2c..99aefdf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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:#}")] diff --git a/src/logfile/archive/rar.rs b/src/logfile/archive/rar.rs index c2815a2..18d5b79 100644 --- a/src/logfile/archive/rar.rs +++ b/src/logfile/archive/rar.rs @@ -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, } impl RarArchive { pub fn new(path: &str) -> Result { - 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, index: usize, name: String, } @@ -29,7 +29,9 @@ impl ArchiveEntry for RarEntry<'_> { } fn extract(self) -> Result, 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> { 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::>() + .into_iter() } }