MCPcopy Create free account
hub / github.com/AI45Lab/Code / normalize_absolute_path

Function normalize_absolute_path

core/src/workspace/local.rs:630–656  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

628}
629
630fn normalize_absolute_path(path: &Path) -> Result<PathBuf> {
631 let lexical = normalize_absolute_path_lexical(path)?;
632 if let Ok(canonical) = lexical.canonicalize() {
633 return Ok(canonical);
634 }
635
636 let mut current = lexical.as_path();
637 let mut suffix = Vec::new();
638 while !current.exists() {
639 let Some(file_name) = current.file_name() else {
640 return Ok(lexical);
641 };
642 suffix.push(file_name.to_os_string());
643 let Some(parent) = current.parent() else {
644 return Ok(lexical);
645 };
646 current = parent;
647 }
648
649 let mut normalized = current.canonicalize().unwrap_or_else(|_| {
650 normalize_absolute_path_lexical(current).unwrap_or_else(|_| current.into())
651 });
652 for part in suffix.iter().rev() {
653 normalized.push(part);
654 }
655 Ok(normalized)
656}
657
658fn normalize_absolute_path_lexical(path: &Path) -> Result<PathBuf> {
659 let mut out = PathBuf::new();

Callers 1

normalize_local_pathFunction · 0.85

Calls 2

existsMethod · 0.45

Tested by

no test coverage detected