Skip to content

Commit

Permalink
Merge pull request #37 from keszybz/pyc-parsing-2
Browse files Browse the repository at this point in the history
Rewrite the pyc handler to use references for all repeated objects
  • Loading branch information
keszybz authored Oct 11, 2024
2 parents b31bd2d + f784a15 commit 885ac77
Show file tree
Hide file tree
Showing 813 changed files with 1,173 additions and 214 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ itertools = "0.13.0"
log = { version = "0.4", features = ["std"] }
nix = { version = "0.28.0", features = ["fs", "socket"] }
num-bigint-dig = "0.8.4"
num-integer = "0.1.46"
num-traits = "0.2.19"
regex = { version = "1.10.0", default-features = false, features = ["std", "perf", "unicode-case"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_cbor = "0.11"
Expand Down
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ struct Options {
#[arg(long)]
pub check: bool,

/// Ignore file name extensions, always run handlers.
#[arg(long)]
pub ignore_extension: bool,

/// Print contents of files
#[arg(short, long,
conflicts_with = "brp",
conflicts_with = "check",
conflicts_with = "job_socket",
conflicts_with = "result_socket",
conflicts_with = "jobs")]
pub print: bool,

/// Read paths to process from this socket.
/// When used, an explicit list of handlers must be given.
#[arg(long,
Expand Down Expand Up @@ -65,9 +78,11 @@ pub struct Config {
pub inputs: Vec<PathBuf>,
pub brp: bool,
pub verbose: bool,
pub print: bool,
pub job_socket: Option<RawFd>,
pub result_socket: Option<RawFd>,
pub check: bool,
pub ignore_extension: bool,
pub jobs: Option<u32>,
pub source_date_epoch: Option<i64>,
pub handler_names: Vec<&'static str>,
Expand Down Expand Up @@ -193,9 +208,11 @@ impl Config {
inputs: options.inputs,
brp: options.brp,
verbose: options.verbose,
print: options.print,
job_socket: options.job_socket,
result_socket: options.result_socket,
check: options.check,
ignore_extension: options.ignore_extension,
jobs,
source_date_epoch,
handler_names,
Expand All @@ -210,9 +227,11 @@ impl Config {
inputs: vec![],
brp: false,
verbose: false,
print: false,
job_socket: None,
result_socket: None,
check,
ignore_extension: false,
jobs: None,
source_date_epoch: Some(source_date_epoch),
handler_names: vec![],
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/ar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl super::Processor for Ar {
}

fn filter(&self, path: &Path) -> Result<bool> {
Ok(path.extension().is_some_and(|x| x == "a"))
Ok(self.config.ignore_extension || path.extension().is_some_and(|x| x == "a"))
}

fn process(&self, input_path: &Path) -> Result<super::ProcessResult> {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl super::Processor for Jar {
}

fn filter(&self, path: &Path) -> Result<bool> {
Ok(path.extension().is_some_and(|x| x == "jar"))
Ok(self.config.ignore_extension || path.extension().is_some_and(|x| x == "jar"))
}

fn process(&self, input_path: &Path) -> Result<super::ProcessResult> {
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/javadoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ impl super::Processor for Javadoc {
}

fn filter(&self, path: &Path) -> Result<bool> {
Ok(path.extension().is_some_and(|x| x == "html")
// && path.to_str().is_some_and(|x| x.contains("/usr/share/javadoc/"))
Ok(
self.config.ignore_extension ||
path.extension().is_some_and(|x| x == "html")
// && path.to_str().is_some_and(|x| x.contains("/usr/share/javadoc/"))
)
}

Expand Down
17 changes: 17 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use log::{log, debug, info, warn, Level};
use serde::{Serialize, Deserialize};
use std::ascii::escape_default;
use std::collections::HashMap;
use std::fmt::Write;
use std::ffi::OsStr;
use std::fs;
use std::fs::{File, Metadata};
Expand Down Expand Up @@ -218,6 +219,22 @@ pub fn inodes_seen() -> HashMap<u64, u8> {
HashMap::new()
}

pub fn do_print(config: &Rc<config::Config>) -> Result<()> {
let handler = pyc::Pyc::new(config);
let mut w = String::new();

for (n, input_path) in config.inputs.iter().enumerate() {
if n > 0 {
writeln!(w)?; // separate outputs by empty line
}
handler.pretty_print(&mut w, input_path)?;
}

print!("{}", w);

Ok(())
}

pub fn do_normal_work(config: &Rc<config::Config>) -> Result<Stats> {
let handlers = make_handlers(config)?;
let mut inodes_seen = inodes_seen();
Expand Down
Loading

0 comments on commit 885ac77

Please sign in to comment.