diff --git a/src/ebuild/repo/mod.rs b/src/ebuild/repo/mod.rs index 53ad6f7..f484e87 100644 --- a/src/ebuild/repo/mod.rs +++ b/src/ebuild/repo/mod.rs @@ -17,7 +17,9 @@ use crate::{ #[derive(Debug, thiserror::Error)] pub enum Error { #[error("io error: {0}")] - Io(#[from] io::Error), + Io(PathBuf, io::Error), + #[error("error while reading directory: {0:?}: {1}")] + ReadDir(PathBuf, io::Error), #[error("failed to decode path: {0}")] Unicode(PathBuf), #[error("parser error: {0}")] @@ -38,10 +40,10 @@ pub struct Category { } #[derive(Debug)] -pub struct Categories(fs::ReadDir); +pub struct Categories(PathBuf, fs::ReadDir); #[derive(Debug)] -pub struct Ebuilds(fs::ReadDir); +pub struct Ebuilds(PathBuf, fs::ReadDir); impl Repo { pub fn new>(path: P) -> Self { @@ -51,15 +53,21 @@ impl Repo { } pub fn categories(&self) -> Result { - Ok(Categories(fs::read_dir( - self.path.as_path().join("metadata/md5-cache"), - )?)) + let path = self.path.as_path().join("metadata/md5-cache"); + + Ok(Categories( + path.clone(), + fs::read_dir(&path).map_err(|e| Error::Io(path, e))?, + )) } } impl Category { pub fn ebuilds(&self) -> Result { - Ok(Ebuilds(fs::read_dir(self.path.as_path())?)) + Ok(Ebuilds( + self.path.clone(), + fs::read_dir(&self.path).map_err(|e| Error::Io(self.path.clone(), e))?, + )) } } @@ -67,12 +75,12 @@ impl Iterator for Categories { type Item = Result; fn next(&mut self) -> Option { - match self.0.next()? { + match self.1.next()? { Ok(entry) => match read_category(entry.path()) { Ok(category) => Some(Ok(category)), Err(e) => Some(Err(e)), }, - Err(e) => Some(Err(Error::Io(e))), + Err(e) => Some(Err(Error::ReadDir(self.0.clone(), e))), } } } @@ -81,7 +89,7 @@ impl Iterator for Ebuilds { type Item = Result; fn next(&mut self) -> Option { - match self.0.next()? { + match self.1.next()? { Ok(entry) => match read_ebuild(entry.path()) { Ok(ebuild) => Some(Ok(ebuild)), Err(e) => Some(Err(e)), @@ -119,7 +127,7 @@ fn read_ebuild(path: PathBuf) -> Result { .parse_finished(InputIter::new(file_name)) .map_err(|_| Error::Parser(file_name.to_string()))?; - let metadata = fs::read_to_string(path.as_path())?; + let metadata = fs::read_to_string(path.as_path()).map_err(|e| Error::Io(path, e))?; Ok(Ebuild { name,