| 177 | } |
| 178 | |
| 179 | pub async fn read_to_string(&self, path: impl AsRef<Path>) -> io::Result<String> { |
| 180 | match self { |
| 181 | Self::Real => fs::read_to_string(path).await, |
| 182 | Self::Chroot(root) => fs::read_to_string(append(root.path(), path)).await, |
| 183 | Self::Fake(map) => { |
| 184 | let Ok(lock) = map.lock() else { |
| 185 | return Err(io::Error::other("poisoned lock")); |
| 186 | }; |
| 187 | let Some(data) = lock.get(path.as_ref()) else { |
| 188 | return Err(io::Error::new(io::ErrorKind::NotFound, "not found")); |
| 189 | }; |
| 190 | match String::from_utf8(data.clone()) { |
| 191 | Ok(string) => Ok(string), |
| 192 | Err(err) => Err(io::Error::new(io::ErrorKind::InvalidData, err)), |
| 193 | } |
| 194 | }, |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | pub fn read_to_string_sync(&self, path: impl AsRef<Path>) -> io::Result<String> { |
| 199 | match self { |