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

Method read_to_string

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

Source from the content-addressed store, hash-verified

531 }
532
533 fn read_to_string(&self, path: &Path) -> Result<String> {
534 #[cfg(test)]
535 {
536 if let Some(&delay) = self.delays.read().unwrap().get(path) {
537 std::thread::sleep(std::time::Duration::from_millis(delay));
538 }
539 }
540
541 if let Some(vf) = self.get_virtual_entry(path) {
542 if vf.is_dir {
543 return Err(Error::other("Is a directory"));
544 }
545 return Ok(vf.content.to_string());
546 }
547
548 if self.is_allowed(path) {
549 if let Ok(content) = self.physical.read_to_string(path) {
550 count_read(content.len());
551 return Ok(content);
552 }
553 }
554
555 // If direct lookup fails on both virtual and physical FS, check across rootDirs virtual merging
556 if let Some(resolved) = self.resolve_across_root_dirs(path) {
557 if let Some(vf) = self.get_virtual_entry(&resolved) {
558 if vf.is_dir {
559 return Err(Error::other("Is a directory"));
560 }
561 return Ok(vf.content.to_string());
562 }
563 if self.is_allowed(&resolved) {
564 let res = self.physical.read_to_string(&resolved);
565 if let Ok(content) = &res {
566 count_read(content.len());
567 }
568 return res;
569 }
570 }
571
572 Err(Error::from(std::io::ErrorKind::NotFound))
573 }
574
575 fn metadata(&self, path: &Path) -> Result<FileMetadata> {
576 if let Some(vf) = self.get_virtual_entry(path) {

Callers 7

test_virtual_file_readFunction · 0.45
test_path_normalizationFunction · 0.45
test_not_found_errorFunction · 0.45
test_fallback_to_real_fsFunction · 0.45
test_virtual_shadowingFunction · 0.45
test_create_test_fsFunction · 0.45

Calls 8

count_readFunction · 0.85
get_virtual_entryMethod · 0.80
is_allowedMethod · 0.80
getMethod · 0.65
unwrapMethod · 0.65
readMethod · 0.65
lenMethod · 0.45

Tested by 7

test_virtual_file_readFunction · 0.36
test_path_normalizationFunction · 0.36
test_not_found_errorFunction · 0.36
test_fallback_to_real_fsFunction · 0.36
test_virtual_shadowingFunction · 0.36
test_create_test_fsFunction · 0.36