use crate::core::error::{Error, Result};
use std::path::{Path, PathBuf};
pub struct OvmfFirmware {
cache_dir: PathBuf,
}
impl OvmfFirmware {
pub fn new(cache_dir: PathBuf) -> Self {
Self { cache_dir }
}
#[cfg(feature = "uefi")]
pub fn fetch(&self) -> Result<OvmfFiles> {
use ovmf_prebuilt::{Arch, FileType, Prebuilt, Source};
std::fs::create_dir_all(&self.cache_dir)?;
let prebuilt = Prebuilt::fetch(Source::LATEST, &self.cache_dir)
.map_err(|e| Error::firmware(format!("failed to fetch OVMF: {}", e)))?;
let code = prebuilt.get_file(Arch::X64, FileType::Code).to_path_buf();
let vars = prebuilt.get_file(Arch::X64, FileType::Vars).to_path_buf();
Ok(OvmfFiles { code, vars })
}
#[cfg(not(feature = "uefi"))]
pub fn fetch(&self) -> Result<OvmfFiles> {
Err(Error::feature_not_enabled("uefi"))
}
}
#[derive(Debug, Clone)]
pub struct OvmfFiles {
pub code: PathBuf,
pub vars: PathBuf,
}
impl OvmfFiles {
pub fn code(&self) -> &Path {
&self.code
}
pub fn vars(&self) -> &Path {
&self.vars
}
}