From b08291dca4d6ea5f4874ca4fc265fce76c20e5cb Mon Sep 17 00:00:00 2001 From: Cno Date: Sun, 14 Jul 2024 04:06:52 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E8=A7=A3=E6=9E=84?= =?UTF-8?q?=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entrances/utils/package.rs | 16 ++++------------ src/executor/mod.rs | 7 ++++--- src/parsers/package.rs | 30 +++++++++++++++--------------- src/utils/log.rs | 6 ++---- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/entrances/utils/package.rs b/src/entrances/utils/package.rs index e284da6d..c3f93213 100644 --- a/src/entrances/utils/package.rs +++ b/src/entrances/utils/package.rs @@ -121,12 +121,8 @@ fn normal_unpack_nep( let inner_pkg_str = outer_validator(&temp_dir_outer_str, &signature_struct.raw_name_stem)?; if verify_signature { log!("Info:Verifying package signature..."); - if signature_struct.signature.is_some() { - let check_res = verify( - &inner_pkg_str, - &signature_struct.signer, - &signature_struct.signature.unwrap(), - )?; + if let Some(sign) = signature_struct.signature { + let check_res = verify(&inner_pkg_str, &signature_struct.signer, &sign)?; if !check_res { return Err(anyhow!( "Error:Failed to verify package signature, this package may have been hacked" @@ -218,12 +214,8 @@ fn fast_unpack_nep( .unwrap(); if verify_signature { log!("Info:Verifying package signature..."); - if signature_struct.signature.is_some() { - let check_res = fast_verify( - inner_pkg_raw, - &signature_struct.signer, - &signature_struct.signature.unwrap(), - )?; + if let Some(sign) = signature_struct.signature { + let check_res = fast_verify(inner_pkg_raw, &signature_struct.signer, &sign)?; if !check_res { return Err(anyhow!( "Error:Failed to verify package signature, this package may have been hacked" diff --git a/src/executor/mod.rs b/src/executor/mod.rs index 04267908..eaf82387 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -72,9 +72,10 @@ pub fn workflow_executor( let name = flow_node.header.name.unwrap(); log!("Debug:Start step '{name}'"); // 解释节点条件,判断是否需要跳过执行 - let c_if = flow_node.header.c_if; - if c_if.is_some() && !condition_eval(&c_if.unwrap(), cx.exit_code, &located)? { - continue; + if let Some(c_if) = flow_node.header.c_if { + if !condition_eval(&c_if, cx.exit_code, &located)? { + continue; + } } // 创建变量解释器 diff --git a/src/parsers/package.rs b/src/parsers/package.rs index 1a0fce55..55f24353 100644 --- a/src/parsers/package.rs +++ b/src/parsers/package.rs @@ -136,26 +136,26 @@ pub fn parse_package( let mut pkg = pkg.interpret(interpreter); // 跟随主程序 exe 文件版本号或是注册表入口 ID 更新版本号 - if need_update_main_program && software.main_program.is_some() { - if let Err(e) = update_ver_with_main_program( - &mut pkg, - &software.main_program.unwrap(), - located, - package_path, - ) { - log!( - "Warning:Failed to update main program version for '{name}' : {e}", - name = pkg.package.name, - ); + if need_update_main_program { + if let Some(main_program) = software.main_program { + if let Err(e) = + update_ver_with_main_program(&mut pkg, &main_program, located, package_path) + { + log!( + "Warning:Failed to update main program version for '{name}' : {e}", + name = pkg.package.name, + ); + } } } - if need_update_main_program && software.registry_entry.is_some() { - let registry_entry = software.registry_entry.unwrap(); - if let Err(e) = update_ver_with_reg_entry(&mut pkg, ®istry_entry, package_path) { - log!( + if need_update_main_program { + if let Some(registry_entry) = software.registry_entry { + if let Err(e) = update_ver_with_reg_entry(&mut pkg, ®istry_entry, package_path) { + log!( "Warning:Failed to update main program version for '{name}' with reg entry '{registry_entry}' : {e}", name = pkg.package.name, ); + } } } diff --git a/src/utils/log.rs b/src/utils/log.rs index 6397d4f3..e01c88ea 100644 --- a/src/utils/log.rs +++ b/src/utils/log.rs @@ -45,8 +45,7 @@ fn gen_log(msg: &String, replace_head: Option) -> Option { pub fn fn_log(msg: String) { let g = gen_log(&msg, None); - if g.is_some() { - let content = g.unwrap(); + if let Some(content) = g { envmnt::set("LAST_LOG", &msg); TERM.write_line(&content).unwrap(); } @@ -54,8 +53,7 @@ pub fn fn_log(msg: String) { pub fn fn_log_ok_last(msg: String) { let g = gen_log(&format!("{msg} {ok}", ok = "ok".green()), None); - if g.is_some() { - let content = g.unwrap(); + if let Some(content) = g { let last_log = envmnt::get_or("LAST_LOG", ""); if last_log == msg { TERM.move_cursor_up(1).unwrap();