zombienet_support/
fs.rs

1use std::path::Path;
2
3use async_trait::async_trait;
4
5pub mod in_memory;
6pub mod local;
7
8#[derive(Debug, thiserror::Error)]
9#[error(transparent)]
10pub struct FileSystemError(#[from] anyhow::Error);
11
12impl From<std::io::Error> for FileSystemError {
13    fn from(error: std::io::Error) -> Self {
14        Self(error.into())
15    }
16}
17
18pub type FileSystemResult<T> = Result<T, FileSystemError>;
19
20#[async_trait]
21pub trait FileSystem {
22    async fn create_dir<P>(&self, path: P) -> FileSystemResult<()>
23    where
24        P: AsRef<Path> + Send;
25
26    async fn create_dir_all<P>(&self, path: P) -> FileSystemResult<()>
27    where
28        P: AsRef<Path> + Send;
29
30    async fn read<P>(&self, path: P) -> FileSystemResult<Vec<u8>>
31    where
32        P: AsRef<Path> + Send;
33
34    async fn read_to_string<P>(&self, path: P) -> FileSystemResult<String>
35    where
36        P: AsRef<Path> + Send;
37
38    async fn write<P, C>(&self, path: P, contents: C) -> FileSystemResult<()>
39    where
40        P: AsRef<Path> + Send,
41        C: AsRef<[u8]> + Send;
42
43    async fn append<P, C>(&self, path: P, contents: C) -> FileSystemResult<()>
44    where
45        P: AsRef<Path> + Send,
46        C: AsRef<[u8]> + Send;
47
48    async fn copy<P1, P2>(&self, from: P1, to: P2) -> FileSystemResult<()>
49    where
50        P1: AsRef<Path> + Send,
51        P2: AsRef<Path> + Send;
52
53    async fn set_mode<P>(&self, path: P, perm: u32) -> FileSystemResult<()>
54    where
55        P: AsRef<Path> + Send;
56
57    async fn exists<P>(&self, path: P) -> bool
58    where
59        P: AsRef<Path> + Send;
60}