meow meow

This commit is contained in:
2025-11-09 21:51:23 +04:00
parent 5c8dc86640
commit b08a3c682e
4 changed files with 270 additions and 85 deletions

38
src/nix_path.rs Normal file
View File

@@ -0,0 +1,38 @@
const NIX_STORE_PREFIX: &str = "/nix/store/";
const NIX_HASH_LENGTH: usize = 32;
pub fn extract_package_name(path: &str) -> Option<String> {
let without_prefix = path.strip_prefix(NIX_STORE_PREFIX)?;
if without_prefix.len() <= NIX_HASH_LENGTH + 1 {
return None;
}
let after_hash = &without_prefix[NIX_HASH_LENGTH + 1..];
let parts: Vec<&str> = after_hash.split('-').collect();
if parts.is_empty() {
return None;
}
let name_parts: Vec<&str> = parts
.iter()
.take_while(|part| !part.chars().next().map_or(false, |c| c.is_ascii_digit()))
.copied()
.collect();
if name_parts.is_empty() {
return None;
}
Some(name_parts.join("-"))
}
pub fn extract_full_name(path: &str) -> Option<&str> {
let without_prefix = path.strip_prefix(NIX_STORE_PREFIX)?;
if without_prefix.len() <= NIX_HASH_LENGTH + 1 {
return None;
}
Some(&without_prefix[NIX_HASH_LENGTH + 1..])
}