summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-12-12 01:59:57 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-12-14 01:37:49 +0000
commita09241dc8940d0a9b01a698d3e71d08f71fadea4 (patch)
tree99e2a6e378c03fe133366faa101352cda1df0248 /src
parent682cfdac9f88b614f502c6352d72a051b6de9440 (diff)
downloadgentoo-utils-a09241dc8940d0a9b01a698d3e71d08f71fadea4.tar.gz
read repo_name when opening repos
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/repo/mod.rs20
-rw-r--r--src/repo/profile/mod.rs3
3 files changed, 21 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b7b01a7..66cf2b9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -69,7 +69,8 @@ pub mod atom;
/// ```
/// use gentoo_utils::repo::Repo;
///
-/// let repo = Repo::new("/var/db/repos/gentoo");
+/// let repo = Repo::new("/var/db/repos/gentoo")
+/// .expect("failed to open repo");
///
/// for result in repo.categories().expect("failed to read categories") {
/// let category = result.expect("failed to read category");
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index 750cd15..165f96a 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -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> {
diff --git a/src/repo/profile/mod.rs b/src/repo/profile/mod.rs
index 8bdb724..28c6b06 100644
--- a/src/repo/profile/mod.rs
+++ b/src/repo/profile/mod.rs
@@ -2,7 +2,8 @@
//! ```rust
//! use gentoo_utils::repo::Repo;
//!
-//! let repo = Repo::new("/var/db/repos/gentoo");
+//! let repo = Repo::new("/var/db/repos/gentoo")
+//! .expect("failed to open repo");
//! let profile = repo.evaluate_profile("default/linux/23.0")
//! .expect("failed to evaluate profile");
//!