Skip to main content

add_extract_util

Function add_extract_util 

Source
pub fn add_extract_util(lua: &Lua, quiet: bool) -> Result<(), Error>
Expand description

Exposes the UTILS.EXTRACT function to the Lua environment.

This utility provides a unified interface for downloading and extracting various archive formats. It handles:

  • Remote Fetching: If the source starts with http(s), it downloads the file to BUILD_DIR.
  • Format Detection: Dispatches to the appropriate decoder (Zip, Tar, Zstd, Xz, 7z, etc.).
  • Error Propagation: Any failure (network, filesystem, or corruption) is converted into an mlua::Error::RuntimeError, which halts the Lua execution and is caught by the Rust build engine to trigger a rollback.

§Errors

Returns an mlua::Error if:

  • The UTILS table cannot be found.
  • The output directory is invalid (not a subdirectory of BUILD_DIR).
  • Filesystem operations (create dir, open file, copy, remove) fail.
  • Network download fails.
  • Archive extraction fails.
  • The archive format is unsupported.

§Panics

This function may panic if:

  • Parsing the source URL fails to yield a filename.
  • Executing external commands (hdiutil, pkgutil, unrar) fails or their output cannot be parsed.