read global package.mask
This commit is contained in:
@@ -13,7 +13,7 @@ use crate::{
|
||||
atom::{self, Atom},
|
||||
repo::{
|
||||
ebuild::{Depend, Eapi, Ebuild, Eclass, License, SrcUri},
|
||||
profile::Profile,
|
||||
profile::{LineBasedFileExpr, Profile},
|
||||
},
|
||||
useflag::IUseFlag,
|
||||
};
|
||||
@@ -43,6 +43,8 @@ pub struct Repo {
|
||||
path: PathBuf,
|
||||
#[get(kind = "deref")]
|
||||
name: String,
|
||||
#[get(kind = "deref")]
|
||||
package_mask: Vec<Atom>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Get)]
|
||||
@@ -69,9 +71,19 @@ impl Repo {
|
||||
Err(e) => return Err(Error::Io(name_path, e)),
|
||||
};
|
||||
|
||||
let package_mask_path = path.as_ref().join("profiles/package.mask");
|
||||
let package_mask =
|
||||
match fs::read_to_string(&package_mask_path).map(|s| read_package_mask(&s)) {
|
||||
Ok(Ok(package_mask)) => package_mask,
|
||||
Ok(Err(e)) => return Err(e),
|
||||
Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => Vec::new(),
|
||||
Err(e) => return Err(Error::Io(package_mask_path, e)),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
path: path.as_ref().to_path_buf(),
|
||||
name,
|
||||
package_mask,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -340,6 +352,20 @@ fn read_idepend(input: &str) -> Option<Result<Vec<Depend<Atom>>, Error>> {
|
||||
Some(parse_depends(line))
|
||||
}
|
||||
|
||||
fn read_package_mask(input: &str) -> Result<Vec<Atom>, Error> {
|
||||
Ok(profile::LineBasedFileExpr::<Atom>::parser()
|
||||
.separated_by_with_opt_trailing(ascii_whitespace1())
|
||||
.many()
|
||||
.parse_finished(InputIter::new(input))
|
||||
.map_err(|it| Error::Parser(it.rest().to_string()))?
|
||||
.into_iter()
|
||||
.filter_map(|expr| match expr {
|
||||
LineBasedFileExpr::Comment => None,
|
||||
LineBasedFileExpr::Expr(atom) => Some(atom),
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> {
|
||||
Depend::<Atom>::parser()
|
||||
.separated_by(ascii_whitespace1())
|
||||
|
||||
@@ -32,7 +32,7 @@ mod parsers;
|
||||
mod useflags;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum LineBasedFileExpr<T> {
|
||||
pub(super) enum LineBasedFileExpr<T> {
|
||||
Comment,
|
||||
Expr(T),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user