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

Method upsert_file

packages/compiler-cli/preprocessor/ng-analyze/src/fs.rs:361–392  ·  view source on GitHub ↗

Add or update a virtual file with the given content

(&self, path: PathBuf, content: String)

Source from the content-addressed store, hash-verified

359
360 /// Add or update a virtual file with the given content
361 pub fn upsert_file(&self, path: PathBuf, content: String) {
362 self.has_virtual_files.store(true, Ordering::Relaxed);
363 let spelled = normalize_path_structural(&path).into_owned();
364 let normalized = normalize_path(&spelled).into_owned();
365 let mut files = self.virtual_files.write().unwrap();
366
367 // Ensure parent directories exist as virtual dirs
368 for dir in spelled.ancestors().skip(1) {
369 let key = normalize_path(dir).into_owned();
370 files.entry(key).or_insert_with(|| VirtualFile {
371 content: "".into(),
372 is_dir: true,
373 path: dir.to_path_buf(),
374 });
375 }
376
377 // Add the file itself
378 let old_file = files.insert(
379 normalized,
380 VirtualFile {
381 content: content.into(),
382 is_dir: false,
383 path: spelled,
384 },
385 );
386
387 // Only invalidate the cache if a new file was actually added.
388 // Modifying an existing file does not change its allowed status.
389 if old_file.is_none() {
390 self.is_allowed_cache.write().unwrap().clear();
391 }
392 }
393
394 /// Check if a path is in the virtual filesystem
395 #[cfg(test)]

Calls 8

normalize_pathFunction · 0.85
skipMethod · 0.80
unwrapMethod · 0.65
writeMethod · 0.65
storeMethod · 0.45
insertMethod · 0.45
clearMethod · 0.45