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

Commit

Permalink
chore(toolchain): update project path name to include file name for e…
Browse files Browse the repository at this point in the history
…asier reference (#540)
  • Loading branch information
NathanFlurry committed Oct 2, 2024
1 parent 43515ff commit 03af1d9
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 03af1d9

Please sign in to comment.