mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-06 19:35:13 +02:00
Refactor and enhance debugging in walk.rs and scan.rs
- Removed unused commented-out code in `walk.rs` for improved readability. - Added more `tracing::debug` logs for clearer traceability during file scanning and rule processing. - Improved condition handling and formatting consistency in `scan.rs`. - Simplified error management and removed redundant comments in database-related functions.
This commit is contained in:
parent
80c0bc9845
commit
8bc16ac940
2 changed files with 15 additions and 39 deletions
|
|
@ -49,11 +49,11 @@ pub fn handle(
|
|||
diags = scan_with_index_parallel(&project_name, pool, config)?;
|
||||
}
|
||||
|
||||
if format == "console" || format == "" && config.output.default_format == "console" {
|
||||
tracing::debug!("Found {:?} issues.", diags.len());
|
||||
|
||||
if format == "console" || (format == "" && config.output.default_format == "console") {
|
||||
tracing::debug!("Printing to console");
|
||||
for d in &diags {
|
||||
if d.severity != Severity::High {
|
||||
continue;
|
||||
}
|
||||
let sev_str = match d.severity {
|
||||
Severity::High => style("HIGH").red().bold(),
|
||||
Severity::Medium => style("MEDIUM").yellow().bold(),
|
||||
|
|
@ -85,14 +85,14 @@ fn scan_filesystem(
|
|||
|
||||
rx.into_iter()
|
||||
.flatten()
|
||||
.par_bridge() // rayon hand-off
|
||||
.try_for_each(|path| { // stable API
|
||||
let mut local = run_rules_on_file(&path, cfg).unwrap(); // <- same as before
|
||||
.par_bridge()
|
||||
.try_for_each(|path| {
|
||||
let mut local = run_rules_on_file(&path, cfg).unwrap();
|
||||
let mut guard = acc.lock().unwrap();
|
||||
guard.append(&mut local);
|
||||
Ok::<(), DynError>(()) // explicit error type
|
||||
})?; // propagate first error, if any
|
||||
|
||||
Ok::<(), DynError>(())
|
||||
})?;
|
||||
|
||||
Ok(acc.into_inner().unwrap())
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +101,6 @@ fn scan_with_index_parallel(
|
|||
pool: Arc<Pool<SqliteConnectionManager>>,
|
||||
cfg: &Config,
|
||||
) -> Result<Vec<Diag>, Box<dyn std::error::Error>> {
|
||||
|
||||
// Get the file list once (single connection, no contention)
|
||||
let files = {
|
||||
let idx = Indexer::from_pool(project, &pool)?;
|
||||
idx.get_files(project)?
|
||||
|
|
@ -153,6 +151,7 @@ pub(crate) fn run_rules_on_file(
|
|||
path: &Path,
|
||||
cfg: &Config,
|
||||
) -> Result<Vec<Diag>, Box<dyn std::error::Error>> {
|
||||
tracing::debug!("Running rules on {}", path.to_string_lossy());
|
||||
let bytes = std::fs::read(path)?;
|
||||
|
||||
let mut parser = Parser::new();
|
||||
|
|
@ -187,12 +186,14 @@ pub(crate) fn run_rules_on_file(
|
|||
|
||||
for cq in &compiled {
|
||||
if cfg.scanner.min_severity > cq.meta.severity {
|
||||
tracing::debug!("Skipping rule {} because it's below the minimum severity", cq.meta.id);
|
||||
continue;
|
||||
}
|
||||
let mut matches = cursor.matches(&cq.query, root, &*bytes);
|
||||
while let Some(m) = matches.next() {
|
||||
for cap in m.captures.iter().filter(|c| c.index == 0) {
|
||||
let point = cap.node.start_position();
|
||||
tracing::debug!("Found match for rule {}", cq.meta.id);
|
||||
out.push(Diag {
|
||||
path: path.to_string_lossy().to_string(),
|
||||
line: point.row + 1,
|
||||
|
|
|
|||
29
src/walk.rs
29
src/walk.rs
|
|
@ -72,38 +72,13 @@ pub fn spawn_senders(
|
|||
.threads(worker_thrs)
|
||||
.overrides(overrides)
|
||||
.build_parallel();
|
||||
|
||||
|
||||
/*
|
||||
walker.run(move || {
|
||||
let tx = tx.clone();
|
||||
let mut batch = Vec::<PathBuf>::with_capacity(256);
|
||||
|
||||
Box::new(move |entry| {
|
||||
tracing::debug!("walking: {:?}", entry);
|
||||
|
||||
let mut b = Batcher { tx: tx.clone(), batch: Vec::with_capacity(BATCH_SIZE) };
|
||||
match entry {
|
||||
Ok(e) if e.file_type().is_some_and(|ft| ft.is_file()) => {
|
||||
b.push(e.into_path());
|
||||
tracing::debug!("scanning file: {:?}", b);
|
||||
if batch.len() == BATCH_SIZE {
|
||||
let _ = tx.send(std::mem::take(&mut batch));
|
||||
}
|
||||
}
|
||||
Err(err) => tracing::error!("walk error: {err}"),
|
||||
_ => {}
|
||||
}
|
||||
WalkState::Continue
|
||||
})
|
||||
});
|
||||
*/
|
||||
|
||||
walker.run(move || {
|
||||
let mut batcher = Batcher {
|
||||
tx: tx.clone(),
|
||||
batch: Vec::with_capacity(BATCH_SIZE),
|
||||
};
|
||||
|
||||
|
||||
Box::new(move |entry| {
|
||||
tracing::debug!("walking: {:?}", entry);
|
||||
let e = match entry {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue