Check if a physical path is allowed by the allowed_sources filter
(&self, path: &Path)
| 277 | |
| 278 | /// Check if a physical path is allowed by the allowed_sources filter |
| 279 | pub fn is_allowed(&self, path: &Path) -> bool { |
| 280 | let Some(allowed) = self.allowed_sources.as_ref() else { |
| 281 | return true; |
| 282 | }; |
| 283 | |
| 284 | let check_allowed = |
| 285 | crate::utils::is_ts_source(path) || path.extension().is_some_and(|e| e == "js"); |
| 286 | |
| 287 | if !check_allowed { |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | // Check cache first to avoid expensive normalization, joins, and canonicalization. |
| 292 | { |
| 293 | let cache = self.is_allowed_cache.read().unwrap(); |
| 294 | if let Some(&allowed) = cache.get(path) { |
| 295 | crate::perf::count(Counter::IsAllowedCacheHits, 1); |
| 296 | return allowed; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | crate::perf::count(Counter::IsAllowedCacheMisses, 1); |
| 301 | let is_allowed = self.is_allowed_uncached(path, allowed); |
| 302 | |
| 303 | let mut cache = self.is_allowed_cache.write().unwrap(); |
| 304 | cache.insert(path.to_path_buf(), is_allowed); |
| 305 | is_allowed |
| 306 | } |
| 307 | |
| 308 | fn is_allowed_uncached(&self, path: &Path, allowed: &HashSet<PathBuf>) -> bool { |
| 309 | // 1. Try checking the path normalized as-is (handles absolute paths and relative paths matching relative entries). |
no test coverage detected