| 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) { |