获取现有可用更新的 saID 集合
Signed-off-by: Jia Chao <jiachao2130@126.com>
This commit is contained in:
parent
b4c6fe6a01
commit
946f13f35c
|
@ -10,3 +10,4 @@ toml = { version = "0.8" }
|
||||||
updateinfo-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/updateinfo-xmlparser.git", version = "0.1.0" }
|
updateinfo-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/updateinfo-xmlparser.git", version = "0.1.0" }
|
||||||
cvrf-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" }
|
cvrf-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" }
|
||||||
rpm-rs = { git = "https://git.zhgsun.com:8089/jiachao2130/rpm-rs.git", version = "0.1.0" }
|
rpm-rs = { git = "https://git.zhgsun.com:8089/jiachao2130/rpm-rs.git", version = "0.1.0" }
|
||||||
|
lazy_static = { version = "1.5" }
|
||||||
|
|
|
@ -7,13 +7,13 @@ use updateinfo_xmlparser::{UpdateInfoDb, RpmInfo};
|
||||||
// PackageDb 从 updateinfo 中获取
|
// PackageDb 从 updateinfo 中获取
|
||||||
// 以包名为键,值为一个 Vector ,里面包含更新的不同版本的 rpm 包信息
|
// 以包名为键,值为一个 Vector ,里面包含更新的不同版本的 rpm 包信息
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PacakgeDb {
|
pub struct PackgeDb {
|
||||||
db: HashMap<String, Vec<RpmInfo>>,
|
db: HashMap<String, Vec<RpmInfo>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PacakgeDb {
|
impl PackgeDb {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PacakgeDb {
|
PackgeDb {
|
||||||
db: HashMap::new(),
|
db: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ impl PacakgeDb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn db(&self) -> &HashMap<String, Vec<RpmInfo>> {
|
||||||
|
&self.db
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaDb 为精简版的安全公告集
|
// SaDb 为精简版的安全公告集
|
||||||
|
@ -98,7 +102,7 @@ mod test {
|
||||||
let mut updatedb = UpdateInfoDb::new();
|
let mut updatedb = UpdateInfoDb::new();
|
||||||
updatedb.load_xml(&updatexml).unwrap();
|
updatedb.load_xml(&updatexml).unwrap();
|
||||||
|
|
||||||
let mut pkgdb = PacakgeDb::new();
|
let mut pkgdb = PackgeDb::new();
|
||||||
pkgdb.load_from_updateinfodb(&updatedb);
|
pkgdb.load_from_updateinfodb(&updatedb);
|
||||||
|
|
||||||
let bash_pkgs = pkgdb.db.get("bash").unwrap();
|
let bash_pkgs = pkgdb.db.get("bash").unwrap();
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use rpm_rs::rpm::{
|
use rpm_rs::rpm::{
|
||||||
get_installed_packages,
|
get_installed_packages,
|
||||||
Package,
|
Package,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rpm_rs::rpmio::rpmvercmp;
|
use rpm_rs::rpmio::rpmvercmp;
|
||||||
|
use updateinfo_xmlparser::{UpdateInfoDb, RpmInfo};
|
||||||
|
|
||||||
use crate::cli::Cli;
|
use crate::cli::Cli;
|
||||||
|
use crate::analyzer::db::PackgeDb;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref update_pkgs: PackgeDb= {
|
||||||
|
let mut updatedb = UpdateInfoDb::new();
|
||||||
|
updatedb.load_xml("test/updateinfo.xml").unwrap();
|
||||||
|
|
||||||
|
let mut pkgdb = PackgeDb::new();
|
||||||
|
pkgdb.load_from_updateinfodb(&updatedb);
|
||||||
|
pkgdb
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
|
@ -42,6 +57,7 @@ fn repoter(cli: &Cli) -> crate::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn summary(cli: &Cli) -> crate::Result<()> {
|
fn summary(cli: &Cli) -> crate::Result<()> {
|
||||||
|
let mut sa_ids: HashSet<String> = HashSet::new();
|
||||||
// 当前系统所有已安装的 rpm 包
|
// 当前系统所有已安装的 rpm 包
|
||||||
let installed = get_installed_packages();
|
let installed = get_installed_packages();
|
||||||
// installed 已被消费掉
|
// installed 已被消费掉
|
||||||
|
@ -54,8 +70,30 @@ fn summary(cli: &Cli) -> crate::Result<()> {
|
||||||
latest
|
latest
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// 列出所有已安装的软件包
|
// 获取 sa 更新列表
|
||||||
// latest_installed.iter().for_each(|pkg| println!("{}", pkg.nevra()));
|
for pkg in latest_installed {
|
||||||
|
let name = pkg.name();
|
||||||
|
if let Some(updates) = update_pkgs.db().get(name) {
|
||||||
|
for update in updates {
|
||||||
|
// epoch 判断
|
||||||
|
match (update.epoch(), pkg.epoch()) {
|
||||||
|
(Some(_), None) => {
|
||||||
|
let _ = sa_ids.insert(update.sa().into());
|
||||||
|
},
|
||||||
|
(None, Some(_)) => continue,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// evr 对比
|
||||||
|
if rpmvercmp(&update.evr(), &pkg.evr()) > 0 {
|
||||||
|
sa_ids.insert(update.sa().into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:#?}", sa_ids.len());
|
||||||
|
// TODO: sa -> { rpms, cves }
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user