(path: &Path)
| 628 | } |
| 629 | |
| 630 | fn 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 | |
| 658 | fn normalize_absolute_path_lexical(path: &Path) -> Result<PathBuf> { |
| 659 | let mut out = PathBuf::new(); |
no test coverage detected