read repo_name when opening repos

This commit is contained in:
2025-12-12 01:59:57 +00:00
parent 682cfdac9f
commit a09241dc89
7 changed files with 25 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ pub mod profile;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("invalid repo: {0}")]
Invalid(String),
#[error("io error: {0}")]
Io(PathBuf, io::Error),
#[error("error while reading directory: {0:?}: {1}")]
@@ -39,6 +41,8 @@ pub enum Error {
pub struct Repo {
#[get(kind = "deref")]
path: PathBuf,
#[get(kind = "deref")]
name: String,
}
#[derive(Debug, Clone, Get)]
@@ -55,10 +59,20 @@ pub struct Categories(PathBuf, fs::ReadDir);
pub struct Ebuilds(PathBuf, fs::ReadDir);
impl Repo {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self {
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let name_path = path.as_ref().join("profiles/repo_name");
let name = match fs::read_to_string(&name_path) {
Ok(repo_name) => repo_name,
Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => {
return Err(Error::Invalid("missing repo_name".to_string()));
}
Err(e) => return Err(Error::Io(name_path, e)),
};
Ok(Self {
path: path.as_ref().to_path_buf(),
}
name,
})
}
pub fn categories(&self) -> Result<Categories, Error> {