| 196 | } |
| 197 | |
| 198 | pub fn read_to_string_sync(&self, path: impl AsRef<Path>) -> io::Result<String> { |
| 199 | match self { |
| 200 | Self::Real => std::fs::read_to_string(path), |
| 201 | Self::Chroot(root) => std::fs::read_to_string(append(root.path(), path)), |
| 202 | Self::Fake(map) => { |
| 203 | let Ok(lock) = map.lock() else { |
| 204 | return Err(io::Error::other("poisoned lock")); |
| 205 | }; |
| 206 | let Some(data) = lock.get(path.as_ref()) else { |
| 207 | return Err(io::Error::new(io::ErrorKind::NotFound, "not found")); |
| 208 | }; |
| 209 | match String::from_utf8(data.clone()) { |
| 210 | Ok(string) => Ok(string), |
| 211 | Err(err) => Err(io::Error::new(io::ErrorKind::InvalidData, err)), |
| 212 | } |
| 213 | }, |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /// Creates a future that will open a file for writing and write the entire |
| 218 | /// contents of `contents` to it. |