Skip to content

Commit

Permalink
chore: 优化解构语法
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Jul 13, 2024
1 parent 8eaa56c commit b08291d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
16 changes: 4 additions & 12 deletions src/entrances/utils/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

// 创建变量解释器
Expand Down
30 changes: 15 additions & 15 deletions src/parsers/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &registry_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, &registry_entry, package_path) {
log!(
"Warning:Failed to update main program version for '{name}' with reg entry '{registry_entry}' : {e}",
name = pkg.package.name,
);
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/utils/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ fn gen_log(msg: &String, replace_head: Option<String>) -> Option<String> {

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();
}
}

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();
Expand Down

0 comments on commit b08291d

Please sign in to comment.