rar fixes

This commit is contained in:
Robin Appelman 2025-07-01 17:21:56 +02:00
commit cd36ba9a8f
7 changed files with 51 additions and 25 deletions

View file

@ -29,7 +29,6 @@ xz2 = "0.1.7"
bzip2-rs = "0.1.2" bzip2-rs = "0.1.2"
ruzstd = "0.8.0" ruzstd = "0.8.0"
sevenz-rust2 = "0.13.2" sevenz-rust2 = "0.13.2"
unrar = "0.5.8"
dialoguer = "0.11.0" dialoguer = "0.11.0"
indicatif = { version = "0.17.11", features = ["rayon"] } indicatif = { version = "0.17.11", features = ["rayon"] }
csv = "1.3.1" csv = "1.3.1"
@ -37,6 +36,9 @@ csv = "1.3.1"
[target.'cfg(target_env = "musl")'.dependencies] [target.'cfg(target_env = "musl")'.dependencies]
tikv-jemallocator = "0.6.0" tikv-jemallocator = "0.6.0"
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
unrar = "0.5.8"
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3

34
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1742394900, "lastModified": 1748970125,
"narHash": "sha256-vVOAp9ahvnU+fQoKd4SEXB2JG2wbENkpqcwlkIXgUC0=", "narHash": "sha256-UDyigbDGv8fvs9aS95yzFfOKkEjx1LO3PL3DsKopohA=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "70947c1908108c0c551ddfd73d4f750ff2ea67cd", "rev": "323b5746d89e04b22554b061522dfce9e4c49b18",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -22,11 +22,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1748263617, "lastModified": 1751287849,
"narHash": "sha256-O1xypYFWzYlfiyO3fUZuzRhYac5DGptP+ZhocY9L5tQ=", "narHash": "sha256-tpOX5x+Chodk/v8wYIzncX5Sq7mbKe0mMAWN0leYpCI=",
"owner": "nix-community", "owner": "nix-community",
"repo": "flakelight", "repo": "flakelight",
"rev": "65c783ba2b85910df5a053cb1451e9eb13794c12", "rev": "16a2ab5cdc789682d80c2c8511df338fd13fc1ca",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -44,11 +44,11 @@
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1748205441, "lastModified": 1751383294,
"narHash": "sha256-W+UUBT/l1DSTZo5G43494mRNNspJ2i9jW2QELC9JuMQ=", "narHash": "sha256-Yg24QBWnVojoD7jVH47BFYkMmjWaZKeJNMqCI75bYLo=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "dac3b74a89cebbeb21cc6602e4a346604adbee8b", "rev": "114f11c2a3af921dc5ef459ce7f2636dfab7171e",
"revCount": 49, "revCount": 55,
"type": "git", "type": "git",
"url": "https://codeberg.org/icewind/mill-scale.git" "url": "https://codeberg.org/icewind/mill-scale.git"
}, },
@ -59,16 +59,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1748037224, "lastModified": 1751211869,
"narHash": "sha256-92vihpZr6dwEMV6g98M5kHZIttrWahb9iRPBm1atcPk=", "narHash": "sha256-1Cu92i1KSPbhPCKxoiVG5qnoRiKTgR5CcGSRyLpOd7Y=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f09dede81861f3a83f7f06641ead34f02f37597f", "rev": "b43c397f6c213918d6cfe6e3550abfe79b5d1c51",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-24.11", "ref": "nixos-25.05",
"type": "indirect" "type": "indirect"
} }
}, },
@ -88,11 +88,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1742697269, "lastModified": 1750214276,
"narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=", "narHash": "sha256-1kniuhH70q4TAC/xIvjFYH46aHiLrbIlcr6fdrRwO1A=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "01973c84732f9275c50c5f075dd1f54cc04b3316", "rev": "f9b2b2b1327ff6beab4662b8ea41689e0a57b8d4",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -1,6 +1,6 @@
{ {
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-24.11"; nixpkgs.url = "nixpkgs/nixos-25.05";
flakelight = { flakelight = {
url = "github:nix-community/flakelight"; url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -12,6 +12,9 @@
}; };
outputs = {mill-scale, ...}: outputs = {mill-scale, ...}:
mill-scale ./. { mill-scale ./. {
nixpkgs.config = {
allowUnfreePredicate = pkg: pkg .pname == "unrar";
};
crossTargets = [ crossTargets = [
"x86_64-unknown-linux-musl" "x86_64-unknown-linux-musl"
"x86_64-pc-windows-gnu" "x86_64-pc-windows-gnu"

View file

@ -27,12 +27,19 @@ pub enum ReadError {
Zstd(#[from] FrameDecoderError), Zstd(#[from] FrameDecoderError),
#[error(transparent)] #[error(transparent)]
SevenZip(#[from] sevenz_rust2::Error), SevenZip(#[from] sevenz_rust2::Error),
#[cfg(all(unix, not(target_env = "musl")))]
#[error(transparent)] #[error(transparent)]
Rar(#[from] unrar::error::UnrarError), Rar(#[from] unrar::error::UnrarError),
#[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:#}")]
Utf8(#[from] FromUtf8Error), Utf8(#[from] FromUtf8Error),
#[allow(dead_code)]
#[error("Opening {format} is not supported{details}")]
UnSupportedFormat {
format: &'static str,
details: &'static str,
},
} }
#[derive(Debug, Error)] #[derive(Debug, Error)]

View file

@ -1,3 +1,4 @@
#[cfg(all(unix, not(target_env = "musl")))]
mod rar; mod rar;
mod sevenzip; mod sevenzip;
mod tar; mod tar;
@ -7,6 +8,7 @@ use crate::error::ReadError;
use std::borrow::Cow; use std::borrow::Cow;
use std::io::Read; use std::io::Read;
#[cfg(all(unix, not(target_env = "musl")))]
pub use rar::RarArchive; pub use rar::RarArchive;
pub use sevenzip::SevenZipArchive; pub use sevenzip::SevenZipArchive;
pub use tar::TarArchive; pub use tar::TarArchive;

View file

@ -42,7 +42,6 @@ impl Archive for RarArchive {
.open_for_listing() .open_for_listing()
.into_iter() .into_iter()
.flatten() .flatten()
.into_iter()
.flatten() .flatten()
.map(|header| RarEntry { .map(|header| RarEntry {
archive: self.path.clone(), archive: self.path.clone(),

View file

@ -2,9 +2,9 @@ mod archive;
pub mod logline; pub mod logline;
use crate::error::ReadError; use crate::error::ReadError;
use crate::logfile::archive::{ #[cfg(all(unix, not(target_env = "musl")))]
Archive, ArchiveEntry, RarArchive, SevenZipArchive, TarArchive, ZipArchive, use crate::logfile::archive::RarArchive;
}; use crate::logfile::archive::{Archive, ArchiveEntry, SevenZipArchive, TarArchive, ZipArchive};
use bzip2_rs::DecoderReader; use bzip2_rs::DecoderReader;
use csv::Reader; use csv::Reader;
use dialoguer::Select; use dialoguer::Select;
@ -43,8 +43,21 @@ impl LogFile {
let mut zip = SevenZipArchive::new(file)?; let mut zip = SevenZipArchive::new(file)?;
return select_file(&mut zip); return select_file(&mut zip);
} else if path.ends_with(".rar") { } else if path.ends_with(".rar") {
let mut rar = RarArchive::new(path)?; #[cfg(all(unix, not(target_env = "musl")))]
return select_file(&mut rar); {
let mut rar = RarArchive::new(path)?;
return select_file(&mut rar);
}
#[cfg(target_env = "musl")]
return Err(ReadError::UnSupportedFormat {
format: "raw",
details: " on static builds",
});
#[cfg(not(unix))]
return Err(ReadError::UnSupportedFormat {
format: "raw",
details: " on windows",
});
} }
if let Some(path) = path.strip_suffix(".gz") { if let Some(path) = path.strip_suffix(".gz") {