use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct DebianCrossArchitecture {
pub(crate) repository_arch: &'static str,
pub(crate) gnu_target: &'static str,
}
pub(crate) fn debian_cross_architecture(target_arch: &str) -> Option<DebianCrossArchitecture> {
match target_arch {
"aarch64" => Some(DebianCrossArchitecture {
repository_arch: "arm64",
gnu_target: "aarch64-linux-gnu",
}),
"x86_64" => Some(DebianCrossArchitecture {
repository_arch: "amd64",
gnu_target: "x86_64-linux-gnu",
}),
_ => None,
}
}
pub(crate) fn sha256_file(path: &Path) -> io::Result<String> {
let mut file = File::open(path)?;
let mut hasher = Sha256::new();
let mut buffer = [0_u8; 64 * 1024];
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
hasher.update(&buffer[..bytes_read]);
}
Ok(format!("{:x}", hasher.finalize()))
}
pub(crate) fn nested_cargo_home(install_dir: &Path) -> PathBuf {
install_dir
.parent()
.unwrap_or(install_dir)
.join("libkrun-cargo-home")
}