hexz_cli/cmd/data/
checkout.rs1use anyhow::Result;
4use std::path::Path;
5use colored::Colorize;
6use super::workspace::Workspace;
7use super::mount;
8
9#[allow(unsafe_code)]
11pub fn run(archive: &Path, path: &Path) -> Result<()> {
12 if path.exists() && std::fs::read_dir(path)?.next().is_some() {
13 anyhow::bail!("Directory {} is not empty.", path.display());
14 }
15
16 std::fs::create_dir_all(path)?;
17
18 println!("{} Initializing workspace at {}", "╭".dimmed(), path.display().to_string().cyan());
19 let ws = Workspace::init(path, Some(archive.to_path_buf()))?;
20 let overlay = ws.overlay_path();
21
22 println!("{} Mounting base archive {}", "╰".dimmed(), archive.display().to_string().bright_black());
23 mount::run(
24 &archive.to_string_lossy(),
25 path,
26 true, None, unsafe { libc::getuid() },
30 unsafe { libc::getgid() },
32 Some(overlay),
33 false, Some(&ws.metadata_dir()),
35 )?;
36
37 println!("\n {} Workspace ready.", "✓".green());
38 Ok(())
39}