hexz_cli/cmd/data/
checkout.rs1use super::mount;
4use super::workspace::Workspace;
5use anyhow::Result;
6use colored::Colorize;
7use std::path::Path;
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!(
19 "{} Initializing workspace at {}",
20 "╭".dimmed(),
21 path.display().to_string().cyan()
22 );
23 let ws = Workspace::init(path, Some(archive.to_path_buf()))?;
24 let overlay = ws.overlay_path();
25
26 println!(
27 "{} Mounting base archive {}",
28 "╰".dimmed(),
29 archive.display().to_string().bright_black()
30 );
31 mount::run(
32 &archive.to_string_lossy(),
33 path,
34 true, None, unsafe { libc::getuid() },
38 unsafe { libc::getgid() },
40 Some(overlay),
41 false, Some(&ws.metadata_dir()),
43 )?;
44
45 println!("\n {} Workspace ready.", "✓".green());
46 Ok(())
47}