Get a virtual file by path, checking raw path first then normalized path if needed.
(
&'a self,
path: &Path,
files: &'a HashMap<PathBuf, VirtualFile>,
)
| 403 | |
| 404 | /// Get a virtual file by path, checking raw path first then normalized path if needed. |
| 405 | fn get_virtual_file<'a>( |
| 406 | &'a self, |
| 407 | path: &Path, |
| 408 | files: &'a HashMap<PathBuf, VirtualFile>, |
| 409 | ) -> Option<&'a VirtualFile> { |
| 410 | if let Some(vf) = files.get(path) { |
| 411 | return Some(vf); |
| 412 | } |
| 413 | let normalized = normalize_path(path); |
| 414 | if let Some(vf) = files.get(&*normalized) { |
| 415 | return Some(vf); |
| 416 | } |
| 417 | let clean_path = path |
| 418 | .strip_prefix("/") |
| 419 | .unwrap_or_else(|_| path.strip_prefix(".").unwrap_or(path)); |
| 420 | if let Some((_, vf)) = files.iter().find(|(k, _)| { |
| 421 | let clean_k = k |
| 422 | .strip_prefix("/") |
| 423 | .unwrap_or_else(|_| k.strip_prefix(".").unwrap_or(k)); |
| 424 | clean_k == clean_path |
| 425 | }) { |
| 426 | return Some(vf); |
| 427 | } |
| 428 | None |
| 429 | } |
| 430 | |
| 431 | /// Retrieve a cloned VirtualFile entry if virtual files are enabled. |
| 432 | fn get_virtual_entry(&self, path: &Path) -> Option<VirtualFile> { |
no test coverage detected