mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-27 17:20:06 +08:00
Merge branch 'master' of github.com:jht5945/buildj
This commit is contained in:
@@ -33,36 +33,32 @@ pub fn get_args_as_vec() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn is_buildin_args(args: &Vec<String>) -> bool {
|
||||
match args.len() <= 1 {
|
||||
true => false,
|
||||
false => args.get(1).unwrap().starts_with(":::"),
|
||||
if args.len() <= 1 {
|
||||
false
|
||||
} else {
|
||||
args.get(1).unwrap().starts_with(":::")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_file_integrity(integrity: &str, file_name: &str) -> XResult<bool> {
|
||||
let digest_hex: &str;
|
||||
let calc_digest_hex: String;
|
||||
if integrity.starts_with("sha256:hex-") {
|
||||
digest_hex = &integrity[11..];
|
||||
calc_digest_hex = calc_file_sha256(file_name)?;
|
||||
} else if integrity.starts_with("sha512:hex-") {
|
||||
digest_hex = &integrity[11..];
|
||||
calc_digest_hex = calc_file_sha512(file_name)?;
|
||||
} else if integrity.starts_with("sha1:hex-") {
|
||||
digest_hex = &integrity[9..];
|
||||
calc_digest_hex = calc_file_sha1(file_name)?;
|
||||
} else if integrity.starts_with("md5:hex-") {
|
||||
digest_hex = &integrity[8..];
|
||||
calc_digest_hex = calc_file_md5(file_name)?;
|
||||
} else {
|
||||
return Err(new_box_error(&format!("Not supported integrigty: {}", integrity)));
|
||||
match integrity.find('-') {
|
||||
None => Err(new_box_error(&format!("Not supported integrigty: {}", integrity))),
|
||||
Some(index) => {
|
||||
let digest_hex = &integrity[index+1..];
|
||||
let calc_digest_hex = match &integrity[0..index] {
|
||||
"sha256:hex" => calc_file_digest(&mut Sha256::new(), "SHA256", file_name)?,
|
||||
"sha512:hex" => calc_file_digest(&mut Sha512::new(), "SHA512", file_name)?,
|
||||
"sha1:hex" => calc_file_digest(&mut Sha1::new(), "SHA1", file_name)?,
|
||||
"md5:hex" => calc_file_digest(&mut Md5::new(), "MD5", file_name)?,
|
||||
_ => return Err(new_box_error(&format!("Not supported integrigty: {}", integrity))),
|
||||
};
|
||||
let integrity_verify_result = digest_hex == calc_digest_hex.as_str();
|
||||
if ! integrity_verify_result {
|
||||
print_message(MessageType::ERROR, &format!("Verify integrity failed, expected: {}, actual: {}", digest_hex, calc_digest_hex));
|
||||
}
|
||||
Ok(integrity_verify_result)
|
||||
},
|
||||
}
|
||||
|
||||
let integrity_verify_result = digest_hex == calc_digest_hex.as_str();
|
||||
if ! integrity_verify_result {
|
||||
print_message(MessageType::ERROR, &format!("Verify integrity failed, expected: {}, actual: {}", digest_hex, calc_digest_hex));
|
||||
}
|
||||
Ok(integrity_verify_result)
|
||||
}
|
||||
|
||||
pub fn calc_sha256(d: &[u8]) -> String {
|
||||
@@ -71,26 +67,6 @@ pub fn calc_sha256(d: &[u8]) -> String {
|
||||
sha256.result_str()
|
||||
}
|
||||
|
||||
pub fn calc_file_md5(file_name: &str) -> XResult<String> {
|
||||
let mut digest = Md5::new();
|
||||
calc_file_digest(&mut digest, "MD5", file_name)
|
||||
}
|
||||
|
||||
pub fn calc_file_sha1(file_name: &str) -> XResult<String> {
|
||||
let mut digest = Sha1::new();
|
||||
calc_file_digest(&mut digest, "SHA1", file_name)
|
||||
}
|
||||
|
||||
pub fn calc_file_sha256(file_name: &str) -> XResult<String> {
|
||||
let mut digest = Sha256::new();
|
||||
calc_file_digest(&mut digest, "SHA256", file_name)
|
||||
}
|
||||
|
||||
pub fn calc_file_sha512(file_name: &str) -> XResult<String> {
|
||||
let mut digest = Sha512::new();
|
||||
calc_file_digest(&mut digest, "SHA512", file_name)
|
||||
}
|
||||
|
||||
pub fn calc_file_digest(digest: &mut Digest, digest_alg: &str, file_name: &str) -> XResult<String> {
|
||||
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
||||
let mut f = File::open(file_name)?;
|
||||
|
||||
@@ -337,10 +337,11 @@ fn main() {
|
||||
cmd.arg(f_arg);
|
||||
}
|
||||
if *VERBOSE {
|
||||
print_message(MessageType::DEBUG, "-----Environment variables-----");
|
||||
print_message(MessageType::DEBUG, "-----BEGIN ENVIRONMENT VARIABLES-----");
|
||||
for (k, v) in new_env {
|
||||
print_message(MessageType::DEBUG, &format!("{}={}", k, v));
|
||||
}
|
||||
print_message(MessageType::DEBUG, "-----END ENVIRONMENT VARIABLES-----");
|
||||
}
|
||||
run_command_and_wait(&mut cmd).unwrap_or_else(|err| {
|
||||
print_message(MessageType::ERROR, &format!("Run build command failed: {}", err));
|
||||
|
||||
Reference in New Issue
Block a user