Skip to main content

run

Function run 

Source
pub fn run(
    source: PathBuf,
    memory: Option<PathBuf>,
    output: PathBuf,
    profile: Option<String>,
    encrypt: bool,
    cdc: bool,
) -> Result<()>
Expand description

Executes the build command to create a snapshot using profile-based settings.

This command maps a high-level build profile to low-level packing parameters (compression algorithm, block size, dictionary training) and delegates to the pack command for actual snapshot creation. This provides a simplified interface for users who want optimized settings without manual tuning.

§Arguments

  • source - Path to the source disk image (raw or qcow2 format)
  • memory - Optional path to memory dump file to include in snapshot
  • output - Output path for the generated .st snapshot file
  • profile - Build profile name: “generic”, “eda”, “embedded”, or “ml”
  • encrypt - Enable AES-256-GCM encryption (prompts for password)
  • cdc - Enable content-defined chunking for variable-sized blocks

§Profile Parameter Mapping

The function resolves the profile name to a BuildProfile enum and extracts:

  • Compression algorithm (compression_algo())
  • Block size in bytes (block_size())
  • Dictionary training recommendation (recommended_dict_training())

These parameters are then passed to pack::run() along with CDC settings.

§CDC (Content-Defined Chunking) Parameters

When cdc is enabled, variable-sized blocks are used with FastCDC:

  • min_chunk: 16 KiB minimum chunk size
  • avg_chunk: 64 KiB average chunk size (default block size)
  • max_chunk: 128 KiB maximum chunk size

These defaults can be overridden by calling pack::run() directly.

§Errors

Returns an error if:

  • The source file cannot be opened or read
  • The output path is not writable
  • The encryption password is invalid (if encryption is enabled)
  • Compression or packing operations fail
  • Disk I/O errors occur during processing

§Examples

use std::path::PathBuf;
use hexz_cli::cmd::data::build;

// Build generic snapshot without encryption
build::run(
    PathBuf::from("disk.img"),
    None,
    PathBuf::from("snapshot.hxz"),
    Some("generic".to_string()),
    false,  // no encryption
    false,  // no CDC
)?;

// Build ML profile with encryption and CDC
build::run(
    PathBuf::from("ml-vm.img"),
    None,
    PathBuf::from("ml.hxz"),
    Some("ml".to_string()),
    true,   // encrypt
    true,   // enable CDC
)?;