pub trait Filestore {
fn read<const N: usize>(
&mut self,
path: &PathBuf,
location: Location
) -> Result<Bytes<N>>;
fn write(
&mut self,
path: &PathBuf,
location: Location,
data: &[u8]
) -> Result<()>;
fn exists(&mut self, path: &PathBuf, location: Location) -> bool;
fn remove_file(&mut self, path: &PathBuf, location: Location) -> Result<()>;
fn remove_dir(&mut self, path: &PathBuf, location: Location) -> Result<()>;
fn remove_dir_all(
&mut self,
path: &PathBuf,
location: Location
) -> Result<usize>;
fn locate_file(
&mut self,
location: Location,
underneath: Option<PathBuf>,
filename: PathBuf
) -> Result<Option<PathBuf>>;
fn read_dir_first(
&mut self,
dir: &PathBuf,
location: Location,
not_before: Option<&PathBuf>
) -> Result<Option<(DirEntry, ReadDirState)>>;
fn read_dir_next(
&mut self,
state: ReadDirState
) -> Result<Option<(DirEntry, ReadDirState)>>;
fn read_dir_files_first(
&mut self,
clients_dir: &PathBuf,
location: Location,
user_attribute: Option<UserAttribute>
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>;
fn read_dir_files_next(
&mut self,
state: ReadDirFilesState
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>;
}
Required methods
fn locate_file(
&mut self,
location: Location,
underneath: Option<PathBuf>,
filename: PathBuf
) -> Result<Option<PathBuf>>
Iterate over entries of a directory (both file and directory entries).
This function is modeled after std::fs::read_dir
, within the limitations of our setup.
The not_before
parameter is an optimization for users to locate a specifically named
file in one call - if the filename exists (e.g., my-data.txt
), then return it directly.
In case an entry was found, the returned option also contains state, so the expected
call to read_dir_next
can resume operation.
fn read_dir_next(
&mut self,
state: ReadDirState
) -> Result<Option<(DirEntry, ReadDirState)>>
fn read_dir_next(
&mut self,
state: ReadDirState
) -> Result<Option<(DirEntry, ReadDirState)>>
Continue iterating over entries of a directory.
Return the entry just after the previous one. If it exists, also return state for the following call.
fn read_dir_files_first(
&mut self,
clients_dir: &PathBuf,
location: Location,
user_attribute: Option<UserAttribute>
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>
fn read_dir_files_first(
&mut self,
clients_dir: &PathBuf,
location: Location,
user_attribute: Option<UserAttribute>
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>
Iterate over contents of files inside a directory.
This has no equivalent in std::fs
, it is an optimization to avoid duplicate
calls and a more complicated state machine (interspersing read_dir_first/next calls
with some sort of “fetch data”).
Additionally, files may optionally be filtered via attributes.
fn read_dir_files_next(
&mut self,
state: ReadDirFilesState
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>
fn read_dir_files_next(
&mut self,
state: ReadDirFilesState
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>
Continuation of read_dir_files_first
.