refactor: multiple fixes
- Create unified Arch enum in utils.rs with methods for all naming conventions - Replace 5 duplicate architecture mapping functions with single source of truth - Add memory string validation for QEMU - Add KVM capability verification via ioctl - Fix TOCTOU race in resolv.conf writing using O_EXCL - Extract magic numbers to named constants - Use constants for stack size, buffer sizes, hostname entropy
This commit is contained in:
+6
-29
@@ -144,39 +144,16 @@ fn parse_oci_ref(input: &str, arch: &str) -> Result<ImageSource> {
|
||||
|
||||
/// Map architecture to OCI standard names
|
||||
pub fn map_oci_arch(arch: &str) -> String {
|
||||
match arch {
|
||||
"amd64" | "x86_64" => "amd64".to_string(),
|
||||
"arm64" | "aarch64" => "arm64".to_string(),
|
||||
"armhf" | "armv7" => "arm".to_string(),
|
||||
"riscv64" => "riscv64".to_string(),
|
||||
"ppc64el" | "ppc64le" => "ppc64le".to_string(),
|
||||
"s390x" => "s390x".to_string(),
|
||||
_ => arch.to_string(),
|
||||
}
|
||||
crate::utils::map_oci_arch(arch)
|
||||
}
|
||||
|
||||
/// Map ecr architecture names to distro-specific names
|
||||
pub fn map_arch(distro: Distro, arch: &str) -> String {
|
||||
match distro {
|
||||
Distro::Ubuntu => match arch {
|
||||
"amd64" => "amd64".to_string(),
|
||||
"arm64" => "arm64".to_string(),
|
||||
"armhf" => "armhf".to_string(),
|
||||
"riscv64" => "riscv64".to_string(),
|
||||
"ppc64el" => "ppc64el".to_string(),
|
||||
"s390x" => "s390x".to_string(),
|
||||
_ => arch.to_string(),
|
||||
},
|
||||
Distro::Alpine => match arch {
|
||||
"amd64" => "x86_64".to_string(),
|
||||
"arm64" => "aarch64".to_string(),
|
||||
"armhf" => "armv7".to_string(),
|
||||
"riscv64" => "riscv64".to_string(),
|
||||
"ppc64el" => "ppc64le".to_string(),
|
||||
"s390x" => "s390x".to_string(),
|
||||
_ => arch.to_string(),
|
||||
},
|
||||
}
|
||||
let distro_name = match distro {
|
||||
Distro::Ubuntu => "ubuntu",
|
||||
Distro::Alpine => "alpine",
|
||||
};
|
||||
crate::utils::map_arch_for_distro(distro_name, arch)
|
||||
}
|
||||
|
||||
/// Resolve the download URL for a known distro (optimized path)
|
||||
|
||||
Reference in New Issue
Block a user