Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

chore(toolchain): update project path name to include file name for easier reference #540

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/toolchain/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ pub fn project_root() -> Result<PathBuf> {
/// Returns a unique hash to the current project's path.
pub fn project_path_hash() -> Result<String> {
let project_root = project_root()?;

// Build clean file name
let file_name = project_root
.file_name()
.map(|name| name.to_string_lossy().to_lowercase())
.unwrap_or_default()
.replace(|c: char| !c.is_alphanumeric(), "_");

// Hash the full path to ensure it's unique
let mut hasher = Sha1::new();
hasher.update(project_root.to_string_lossy().as_bytes());
Ok(format!("{:x}", hasher.finalize()))
let hash = format!("{:.16x}", hasher.finalize());

// Return a human-readable name
Ok(format!("{}_{}", file_name, hash))
}

/// Where all data gets stored globally.
Expand Down
Loading