Something went wrong. Try again.
Flatpak-style launcher for sandboxed WebAssembly tools. Install, verify, and run .wasm binaries with explicit capability grants. Single binary, local-first, zero telemetry. wasmbox.orbiter.website
wasm rust wasmbox
Something went wrong. Try again.
2.8 kB · 102 lines
Rust
at dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
/// A configured registry in config.toml.#[derive(Debug, Clone, Serialize, Deserialize)]pub struct RegistryConfig { pub url: String, #[serde(default)] pub name: Option<String>,}
/// Contents of ~/.wasmbox/config.toml.#[derive(Debug, Clone, Serialize, Deserialize, Default)]pub struct WasmBoxConfig { #[serde(default)] pub registries: Vec<RegistryConfig>,}
impl WasmBoxConfig { pub fn load(path: &Path) -> Result<Self, Box<dyn std::error::Error>> { if path.exists() { let content = std::fs::read_to_string(path)?; Ok(toml::from_str(&content)?) } else { Ok(Self::default()) } }
pub fn save(&self, path: &Path) -> Result<(), Box<dyn std::error::Error>> { if let Some(parent) = path.parent() { std::fs::create_dir_all(parent)?; } let content = toml::to_string_pretty(self)?; std::fs::write(path, content)?; Ok(()) }}
/// Resolved paths for all WasmBox directories and files.////// Resolution order: --home flag > WASMBOX_HOME env > ~/.wasmbox/#[derive(Debug, Clone)]pub struct WasmBoxPaths { home: PathBuf,}
impl WasmBoxPaths { /// Create paths from an explicit home directory. pub fn new(home: PathBuf) -> Self { Self { home } }
/// Resolve paths using: explicit override > WASMBOX_HOME env > ~/.wasmbox/ pub fn resolve(cli_override: Option<&str>) -> Self { let home = if let Some(path) = cli_override { PathBuf::from(path) } else if let Ok(path) = std::env::var("WASMBOX_HOME") { PathBuf::from(path) } else { dirs::home_dir() .expect("could not determine home directory") .join(".wasmbox") }; Self { home } }
pub fn home(&self) -> &Path { &self.home }
pub fn config_file(&self) -> PathBuf { self.home.join("config.toml") }
pub fn permissions_file(&self) -> PathBuf { self.home.join("permissions.toml") }
pub fn cache_dir(&self) -> PathBuf { self.home.join("cache") }
pub fn tool_dir(&self, name: &str, version: &str) -> PathBuf { self.cache_dir().join(name).join(version) }
pub fn tool_wasm_path(&self, name: &str, version: &str, wasm_file: &str) -> PathBuf { self.tool_dir(name, version).join(wasm_file) }
pub fn tool_manifest_path(&self, name: &str, version: &str) -> PathBuf { self.tool_dir(name, version).join("wasmbox.toml") }
/// Create all necessary directories. pub fn ensure_dirs(&self) -> std::io::Result<()> { std::fs::create_dir_all(&self.home)?; std::fs::create_dir_all(self.cache_dir())?; Ok(()) }}