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