MCPcopy Create free account
hub / github.com/angular/angular / canonicalize

Method canonicalize

packages/compiler-cli/preprocessor/ng-analyze/src/fs.rs:639–678  ·  view source on GitHub ↗
(&self, path: &Path)

Source from the content-addressed store, hash-verified

637 }
638
639 fn canonicalize(&self, path: &Path) -> Result<PathBuf> {
640 // For virtual files, canonicalize purely by path normalization.
641 if self.get_virtual_entry(path).is_some() {
642 let normalized = normalize_path_structural(path);
643 return Ok(normalized.into_owned());
644 }
645
646 if self.preserve_symlinks.load(Ordering::Relaxed) {
647 crate::perf::count(Counter::FsStatCalls, 1);
648 if path.exists() {
649 let abs_path = if path.is_absolute() {
650 path.to_path_buf()
651 } else {
652 self.cwd.join(path)
653 };
654 return Ok(normalize_path_structural(&abs_path).into_owned());
655 }
656 } else {
657 crate::perf::count(Counter::FsCanonicalizeCalls, 1);
658 match self.physical.canonicalize(path) {
659 Ok(canon) => return Ok(canon),
660 Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
661 Err(e) => return Err(e),
662 }
663 }
664
665 // If direct lookup fails, attempt to canonicalize candidate path resolved across rootDirs.
666 if let Some(resolved) = self.resolve_across_root_dirs(path) {
667 if self.preserve_symlinks.load(Ordering::Relaxed) {
668 return Ok(normalize_path_structural(&resolved).into_owned());
669 }
670 if self.get_virtual_entry(&resolved).is_some() {
671 return Ok(normalize_path_structural(&resolved).into_owned());
672 }
673 crate::perf::count(Counter::FsCanonicalizeCalls, 1);
674 return Ok(self.physical.canonicalize(&resolved).unwrap_or(resolved));
675 }
676
677 Err(Error::from(std::io::ErrorKind::NotFound))
678 }
679}
680
681#[cfg(test)]

Callers

nothing calls this directly

Calls 8

get_virtual_entryMethod · 0.80
loadMethod · 0.65
existsMethod · 0.65
joinMethod · 0.65
canonicalizeMethod · 0.65
countFunction · 0.50

Tested by

no test coverage detected