From 172eb6ab075dfd8f73e9ad730c657db813400c8a Mon Sep 17 00:00:00 2001 From: Jia Chao Date: Thu, 13 Jun 2024 15:51:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=AD=E4=B8=AA=E5=9F=BA=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E6=9E=B6=E5=AD=90=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jia Chao --- Cargo.toml | 4 ++ src/lib.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c87f807..e124238 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +cvrf-xmlparser = { git = "https://git.culinux.net/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" } +serde = { version = "1", features = ["serde_derive"] } +tracing = { version = "0.1" } +xml-rs = { version = "0.8" } diff --git a/src/lib.rs b/src/lib.rs index 7d12d9a..9922e78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,103 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +use cvrf_xmlparser::{Severity, XmlReader}; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateInfoDb { + db: Vec, } -#[cfg(test)] -mod tests { - use super::*; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateInfo { + // sa id + id: String, - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + // sa title + title: String, + + // sa severity + severity: Severity, + + // the product? openEuler/CULinux + release: String, + + // 用处不大,先不用 + //date: String, + + // cve ids,可能有多个 + cves: Vec, + + // 安全公告的描述 + description: String, + + // 此次更新包含的软件包列表 + pkglist: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RpmInfo { + // 包名 + name: String, + // 可能为空 + epoch: String, + + version: String, + + release: String, + + arch: String, + + file: String, +} + +impl RpmInfo { + pub fn new() -> Self { + RpmInfo { + name: String::new(), + epoch: String::new(), + version: String::new(), + release: String::new(), + arch: String::new(), + file: String::new(), + } + } + + pub fn name(&self) -> &str { + &self.name + } + + pub fn epoch(&self) -> Option<&str> { + if self.epoch != "" { + Some(&self.epoch) + } else { + None + } + } + + pub fn version(&self) -> &str { + &self.version + } + + pub fn release(&self) -> &str { + &self.release + } + + pub fn arch(&self) -> &str { + &self.arch + } + + pub fn file(&self) -> &str { + &self.file + } + + pub fn evr(&self) -> String { + if self.epoch().is_some() { + format!("{}:{}-{}", self.epoch, self.version, self.release) + } else { + format!("{}-{}", self.version, self.release) + } + } + + pub fn nevra(&self) -> String { + format!("{}-{}-{}", self.name, self.evr(), self.arch) } }