cubic 0.18.0

Cubic is a lightweight command line manager for virtual machines. It has a simple, daemon-less and rootless design. All Cubic virtual machines run isolated in the user context. Cubic is built on top of QEMU, KVM and cloud-init. https://cubic-vm.org https://github.com/cubic-vm/cubic Show all supported images: $ cubic images Create a new virtual machine instance: $ cubic create mymachine --image ubuntu:noble List all virtual machine instances: $ cubic instances Start an instance: $ cubic start <instance name> Stop an instance: $ cubic stop <instance name> Open a shell in the instance: $ cubic ssh <machine name> Copy a file from the host to the instance: $ cubic scp <path/to/host/file> <machine>:<path/to/guest/file> Copy a file from the instance to the hots: $ cubic scp <machine>:<path/to/guest/file> <path/to/host/file>
use crate::env::Environment;
use crate::error::Error;
use crate::fs::FS;
use crate::image::{Image, ImageStore};
use std::path::Path;

pub struct ImageDao {
    fs: FS,
    pub env: Environment,
}

impl ImageDao {
    pub fn new(env: &Environment) -> Result<Self, Error> {
        let fs = FS::new();
        fs.setup_directory_access(&env.get_image_dir())?;
        Result::Ok(ImageDao {
            fs,
            env: env.clone(),
        })
    }
}

impl ImageStore for ImageDao {
    fn exists(&self, image: &Image) -> bool {
        Path::new(&format!(
            "{}/{}",
            self.env.get_image_dir(),
            image.to_file_name()
        ))
        .exists()
    }

    fn prune(&self) -> Result<(), Error> {
        self.fs.remove_file(&self.env.get_image_cache_file()).ok();
        self.fs.remove_dir(&self.env.get_image_dir())
    }
}