mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-09 19:45:13 +02:00
- Introduced `NyxError` and `NyxResult` for unified error handling across modules. - Refactored `scan.rs`, `index.rs`, and `walk.rs` with improved error management and consistent formatting. - Replaced existing error handling in `database.rs` with `NyxResult`. - Improved database maintenance by integrating `vacuum` and `clear` methods into workflows. - Added `dashmap` for efficient parallel diagnostics result aggregation in `scan_with_index_parallel`. - Enhanced readability and formatting of console outputs in multiple modules.
34 lines
No EOL
964 B
Rust
34 lines
No EOL
964 B
Rust
use std::path::{Path, PathBuf};
|
|
use crate::errors::{NyxError, NyxResult};
|
|
|
|
/// Determine `<project-name, path/to/<project>.sqlite>`.
|
|
pub fn get_project_info(
|
|
project_path: &Path,
|
|
config_dir: &Path,
|
|
) -> NyxResult<(String, PathBuf)> {
|
|
|
|
let project_name = project_path
|
|
.file_name()
|
|
.and_then(|n| n.to_str())
|
|
.ok_or_else(|| NyxError::Other("Unable to determine project name".into()))?;
|
|
|
|
let db_name = sanitize_project_name(project_name);
|
|
let db_path = config_dir.join(format!("{}.sqlite", db_name));
|
|
|
|
Ok((project_name.to_owned(), db_path))
|
|
}
|
|
|
|
pub fn sanitize_project_name(name: &str) -> String {
|
|
name.to_lowercase()
|
|
.chars()
|
|
.map(|c| match c {
|
|
' ' | '\t' | '\n' | '\r' => '_',
|
|
c if c.is_alphanumeric() || c == '_' || c == '-' => c,
|
|
_ => '_',
|
|
})
|
|
.collect::<String>()
|
|
.split('_')
|
|
.filter(|s| !s.is_empty())
|
|
.collect::<Vec<_>>()
|
|
.join("_")
|
|
} |