- Remove unused filetypes.rs and walk.rs modules

- Introduce `index.rs` for file indexing using SQLite
- Expand configuration options in `config.rs`, including `excluded_files`
- Update dependencies in `Cargo.toml` to include SQLite, hashing, and regex libraries
This commit is contained in:
elipeter 2025-06-16 23:47:50 +02:00
parent 646293ed72
commit ada7835efa
11 changed files with 551 additions and 766 deletions

View file

@ -2,6 +2,9 @@ use crate::cli::OutputFormat;
use crate::utils::project::get_project_info;
use std::path::Path;
use crate::utils::config::Config;
use tree_sitter::{Parser};
use crate::index::index::Indexer;
use crate::walk::spawn_senders;
pub fn handle(
path: &str,
@ -15,13 +18,13 @@ pub fn handle(
let scan_path = Path::new(path).canonicalize()?;
let (project_name, db_path) = get_project_info(&scan_path, database_dir)?;
tracing::info!("Config: {:?}", config);
tracing::debug!("Config: {:?}", config);
tracing::info!("Scanning project: {}", project_name);
tracing::info!("Scan path: {}", scan_path.display());
if no_index {
tracing::info!("Scanning without index...");
scan_filesystem(&scan_path)?;
scan_filesystem(&scan_path, config)?;
} else {
if rebuild_index || !db_path.exists() {
tracing::info!("Building/updating index...");
@ -29,7 +32,7 @@ pub fn handle(
}
tracing::info!("Using index: {}", db_path.display());
scan_with_index(&db_path)?;
scan_with_index(&scan_path, &db_path, config)?;
}
tracing::info!("Output format: {:?}", format);
@ -40,14 +43,63 @@ pub fn handle(
Ok(())
}
fn scan_filesystem(path: &Path) -> Result<(), Box<dyn std::error::Error>> {
// TODO: Implement direct filesystem scanning
tracing::info!("Direct filesystem scan of: {}", path.display());
fn scan_filesystem(root: &Path, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
let rx = spawn_senders(root, cfg);
for batch in rx.iter().flatten() {
tracing::debug!("Scanning file: {}", batch.display());
scan_single_file(&batch, cfg)?; // <-- your actual scanner
}
Ok(())
}
fn scan_with_index(root: &Path, db_path: &Path, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
let indexer = Indexer::new(db_path)
.map_err(|e| format!("opening index {}: {e}", db_path.display()))?;
let rx = spawn_senders(root, cfg);
for batch in rx.iter().flatten() {
let scan = indexer.should_scan(&batch)?;
tracing::debug!("Should scan: {}, file: {}", scan, batch.display());
if scan {
tracing::debug!("Scanning file: {}", batch.display());
scan_single_file(&batch, cfg)?; // your scanner
indexer.record_scan(&batch)?;
}
}
Ok(())
}
fn scan_with_index(db_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
// TODO: Implement index-based scanning
tracing::info!("Index-based scan using: {}", db_path.display());
fn scan_single_file(
path: &Path,
_cfg: &Config,
) -> Result<(), Box<dyn std::error::Error>> {
if path.extension().and_then(|s| s.to_str()) != Some("rs") {
return Ok(());
}
let source = std::fs::read_to_string(path)?;
let mut parser = Parser::new();
parser.set_language(&tree_sitter_rust::LANGUAGE.into())?;
let tree = parser.parse(&source, None).ok_or("tree-sitter failed")?;
let root = tree.root_node();
let mut fn_count = 0;
let mut cursor = root.walk();
for child in root.children(&mut cursor) {
if child.kind() == "function_item" {
fn_count += 1;
}
}
tracing::info!(
"scanned {} found {} Rust function(s)",
path.display(),
fn_count
);
// TODO: real vulnerability/pattern checks go here
Ok(())
}