use std::{collections::HashSet, path::PathBuf};
use log::{debug, trace};
use crate::{
error::{FsError, FsResult},
io::FsIo,
};
#[derive(Debug)]
pub struct ReadDir {
path: Option<PathBuf>,
}
impl ReadDir {
pub fn new(path: impl Into<PathBuf>) -> Self {
let input = Some(path.into());
Self { path: input }
}
pub fn resume(&mut self, arg: Option<FsIo>) -> FsResult<HashSet<PathBuf>> {
let Some(arg) = arg else {
let Some(path) = self.path.take() else {
return FsResult::Err(FsError::MissingInput);
};
trace!("wants I/O to read directory at {}", path.display());
return FsResult::Io(FsIo::ReadDir(Err(path)));
};
debug!("resume after reading directory");
let FsIo::ReadDir(io) = arg else {
let err = FsError::InvalidArgument("read dir output", arg);
return FsResult::Err(err);
};
match io {
Ok(paths) => FsResult::Ok(paths),
Err(path) => FsResult::Io(FsIo::ReadDir(Err(path))),
}
}
}