mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
hypha: implement image cache
This commit is contained in:
@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user