From 7e5f30e3e327136a4d278c919484964981b05d1f Mon Sep 17 00:00:00 2001 From: Jia Chao Date: Thu, 25 Jul 2024 14:49:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E6=88=AA=E5=8F=96=E6=AC=A7=E6=8B=89=20rpm=20=E5=8C=85=E7=9A=84?= =?UTF-8?q?=20nvr=20=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jia Chao --- Cargo.toml | 2 ++ src/lib.rs | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c198c8..a761b6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,8 @@ edition = "2021" [dependencies] clap = { version = "4.0", features = ["derive"] } cvrf-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" } +lazy_static = { version = "1" } +regex = { version = "1" } serde = { version = "1", features = ["serde_derive"] } serde_json = { version = "1.0" } tracing = { version = "0.1" } diff --git a/src/lib.rs b/src/lib.rs index ec1ca12..24f9237 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,8 @@ use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; +use lazy_static::lazy_static; +use regex::Regex; use tracing::{debug, error, info, trace}; use tracing_subscriber::{fmt, EnvFilter}; @@ -24,6 +26,14 @@ pub type Error = Box; /// 定义 crate::Result pub type Result = std::result::Result; +lazy_static! { + pub static ref NVR_RE: Regex = Regex::new( + // %{name}-%{version}-%{release}.[oexxxx.xxx.rpm] + r"^([a-zA-Z0-9\-_+]+)-([0-9a-zA-Z\._+]+)-([0-9a-zA-Z\._-]+).(oe[0-9a-z]+.[0-9a-z]+.rpm)" + ) + .unwrap(); +} + pub fn cumain() -> Result<()> { set_up_logging()?; let cli = cli::parse(); @@ -241,8 +251,9 @@ fn _save_2_cusa_db(dbpath: &str, cvrf: &CVRF) -> Result<()> { let component = cvrf.affected_component().unwrap(); trace!("Get affected_component: {}", component); // 这里随便取一个 src 包名 - let _src = cvrf.producttree.packages["src"][0].productid.as_str(); + let _src = cvrf.producttree.packages["src"][0].content.as_str(); + /* // TODO: may empty if _src == "" { error!( @@ -251,8 +262,9 @@ fn _save_2_cusa_db(dbpath: &str, cvrf: &CVRF) -> Result<()> { ); return Ok(()); } + */ db.push(_src.chars().next().unwrap().to_string()); - // TODO!() + // 不理会此问题 // db: "cusas/l/log4j,mybatis,netty,springframework,wildfly-security-manager,wildfly-elytron,wildfly-build-tools,wildfly-common,wildfly-core,thrift,json-lib,datanucleus-core,jgroups,mx4j,jboss-logging,infinispan,datanucleus-rdbms,avalon-logkit,datanucleus-api-jdo,avalon-framework,HikariCP,metrics" // Error: Os { code: 63, kind: InvalidFilename, message: "File name too long" } db.push(component); @@ -269,7 +281,12 @@ fn _save_2_cusa_db(dbpath: &str, cvrf: &CVRF) -> Result<()> { match fs::create_dir_all(parent) { Ok(_) => {} Err(e) => { - error!("sa_id: {}, {}", cvrf.id(), e.to_string()); + error!( + "sa_id: {}, create_dir_all({:?}): {}", + cvrf.id(), + parent, + e.to_string() + ); return Ok(()); } } @@ -309,7 +326,11 @@ fn _save_2_cusa_db(dbpath: &str, cvrf: &CVRF) -> Result<()> { let mut nvr = String::new(); for product in &cvrf.producttree.packages["src"] { if product.cpe.ends_with(repairconfig.upstream()) { - nvr = product.productid.clone(); + nvr = if let Some(caps) = NVR_RE.captures(&product.content) { + format!("{}-{}-{}", &caps[1], &caps[2], &caps[3]) + } else { + product.content.clone() + }; nvr.push_str(&format!("_{}.json", cvrf.id())); break; }