Compare commits
8 Commits
90feca00b6
...
db43560be5
| Author | SHA1 | Date | |
|---|---|---|---|
|
db43560be5
|
|||
|
4544507c00
|
|||
|
13ccf1ed25
|
|||
|
dafdc05dff
|
|||
|
70c8437830
|
|||
|
f3718d143a
|
|||
|
12d362983d
|
|||
|
e67e20ef29
|
@@ -20,7 +20,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
fs::create_dir_all(&corpus_dir)?;
|
||||
|
||||
let repo = Repo::new("/var/db/repos/gentoo");
|
||||
let repo = Repo::new("/var/db/repos/gentoo").expect("failed to open repo");
|
||||
let mut atoms = Vec::new();
|
||||
|
||||
for category in repo.categories()? {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
gencorpus = executable(
|
||||
'gencorpus',
|
||||
'atom_parser_gencorpus',
|
||||
'gencorpus.rs',
|
||||
dependencies: [mon],
|
||||
link_with: [gentoo_utils],
|
||||
)
|
||||
|
||||
corpus = custom_target(
|
||||
'corpus',
|
||||
'atom_parser_corpus',
|
||||
output: 'corpus',
|
||||
command: [gencorpus, 'corpus'],
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
fs::create_dir_all(&corpus_dir)?;
|
||||
|
||||
let repo = Repo::new("/var/db/repos/gentoo");
|
||||
let repo = Repo::new("/var/db/repos/gentoo").expect("failed to open repo");
|
||||
let mut versions = Vec::new();
|
||||
|
||||
for category in repo.categories()? {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
gencorpus = executable(
|
||||
'gencorpus',
|
||||
'atom_vercmp_gencorpus',
|
||||
'gencorpus.rs',
|
||||
dependencies: [mon],
|
||||
link_with: [gentoo_utils],
|
||||
)
|
||||
|
||||
corpus = custom_target(
|
||||
'corpus',
|
||||
'atom_vercmp_corpus',
|
||||
output: 'corpus',
|
||||
command: [gencorpus, 'corpus'],
|
||||
)
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 {
|
||||
path: path.as_ref().to_path_buf(),
|
||||
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> {
|
||||
|
||||
@@ -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");
|
||||
//!
|
||||
|
||||
@@ -474,7 +474,7 @@ fn main() {
|
||||
"prefix/sunos/solaris/5.11/x64",
|
||||
];
|
||||
|
||||
let repo = Repo::new("/var/db/repos/gentoo");
|
||||
let repo = Repo::new("/var/db/repos/gentoo").expect("failed to open repo");
|
||||
|
||||
for profile in profiles {
|
||||
repo.evaluate_profile(profile)
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::error::Error;
|
||||
use gentoo_utils::repo::Repo;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let repo = Repo::new("/var/db/repos/gentoo");
|
||||
let repo = Repo::new("/var/db/repos/gentoo").unwrap();
|
||||
|
||||
for result in repo.categories()? {
|
||||
let cat = result?;
|
||||
|
||||
Reference in New Issue
Block a user