From 97e7e5faacfdf8257eec9ce3eac0eb73723fae72 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Mon, 30 Sep 2024 18:53:35 -0700 Subject: [PATCH] chore(toolchain): update project path name to include file name for easier reference --- packages/toolchain/src/paths.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/toolchain/src/paths.rs b/packages/toolchain/src/paths.rs index 98a5315c..aab6d4ae 100644 --- a/packages/toolchain/src/paths.rs +++ b/packages/toolchain/src/paths.rs @@ -10,9 +10,21 @@ pub fn project_root() -> Result { /// Returns a unique hash to the current project's path. pub fn project_path_hash() -> Result { 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.