hypha: implement image cache

This commit is contained in:
Alex Zenla
2024-01-18 00:02:21 -08:00
parent 9c438e8e57
commit 1c92ba54f3
6 changed files with 149 additions and 25 deletions

View File

@ -1,6 +1,6 @@
use clap::Parser;
use hypha::ctl::Controller;
use hypha::error::Result;
use hypha::error::{HyphaError, Result};
#[derive(Parser, Debug)]
#[command(version, about)]
@ -19,16 +19,38 @@ struct ControllerArgs {
#[arg(short, long, default_value_t = 512)]
mem: u64,
#[arg(short = 'C', long, default_value = "auto")]
cache: String,
}
fn main() -> Result<()> {
env_logger::init();
let args = ControllerArgs::parse();
let mut controller =
Controller::new(args.kernel, args.initrd, args.image, args.cpus, args.mem)?;
controller.compile()?;
let cache_path = if args.cache == "auto" {
default_cache_path()
.ok_or_else(|| HyphaError::new("unable to determine default cache path"))
} else {
Ok(args.cache)
}?;
let mut controller = Controller::new(
cache_path,
args.kernel,
args.initrd,
args.image,
args.cpus,
args.mem,
)?;
let domid = controller.launch()?;
println!("launched domain: {}", domid);
Ok(())
}
fn default_cache_path() -> Option<String> {
let user_dirs = directories::UserDirs::new()?;
let mut path = user_dirs.home_dir().to_path_buf();
path.push(".hypha/cache");
Some(path.to_str()?.to_string())
}