Creates a future that will open a file for writing and write the entire contents of `contents` to it. This is a proxy to [`tokio::fs::write`].
(&self, path: impl AsRef<Path>, contents: impl AsRef<[u8]>)
| 219 | /// |
| 220 | /// This is a proxy to [`tokio::fs::write`]. |
| 221 | pub async fn write(&self, path: impl AsRef<Path>, contents: impl AsRef<[u8]>) -> io::Result<()> { |
| 222 | match self { |
| 223 | Self::Real => fs::write(path, contents).await, |
| 224 | Self::Chroot(root) => fs::write(append(root.path(), path), contents).await, |
| 225 | Self::Fake(map) => { |
| 226 | let Ok(mut lock) = map.lock() else { |
| 227 | return Err(io::Error::other("poisoned lock")); |
| 228 | }; |
| 229 | lock.insert(path.as_ref().to_owned(), contents.as_ref().to_owned()); |
| 230 | Ok(()) |
| 231 | }, |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /// Removes a file from the filesystem. |
| 236 | /// |