From cad64482c0e49ccd5fdde7440e9be42964cd1005 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Wed, 25 Feb 2026 13:24:02 +0100 Subject: [PATCH] chore: trim runtime/store comments --- crates/karapace-runtime/src/namespace.rs | 23 +---------------------- crates/karapace-store/src/wal.rs | 22 ---------------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/crates/karapace-runtime/src/namespace.rs b/crates/karapace-runtime/src/namespace.rs index a69af28..6fe0c87 100644 --- a/crates/karapace-runtime/src/namespace.rs +++ b/crates/karapace-runtime/src/namespace.rs @@ -49,7 +49,6 @@ impl RuntimeBackend for NamespaceBackend { } fn available(&self) -> bool { - // Check that user namespaces work let output = std::process::Command::new("unshare") .args(["--user", "--map-root-user", "--fork", "true"]) .output(); @@ -61,12 +60,10 @@ impl RuntimeBackend for NamespaceBackend { eprintln!("[karapace] {msg}"); }; - // Download/cache the base image let resolved = resolve_image(&spec.manifest.base_image)?; let image_cache = ImageCache::new(&self.store_root); let rootfs = image_cache.ensure_image(&resolved, &progress, spec.offline)?; - // Compute content digest of the base image let base_image_digest = compute_image_digest(&rootfs)?; if spec.offline && !spec.manifest.system_packages.is_empty() { @@ -75,8 +72,6 @@ impl RuntimeBackend for NamespaceBackend { )); } - // If there are packages to resolve, set up a temporary overlay - // and install+query to get exact versions let resolved_packages = if spec.manifest.system_packages.is_empty() { Vec::new() } else { @@ -86,13 +81,11 @@ impl RuntimeBackend for NamespaceBackend { std::fs::create_dir_all(&tmp_env)?; let mut sandbox = SandboxConfig::new(rootfs.clone(), "resolve-tmp", &tmp_env); - sandbox.isolate_network = false; // need network for package resolution + sandbox.isolate_network = false; mount_overlay(&sandbox)?; setup_container_rootfs(&sandbox)?; - // Run resolution inside an inner closure so cleanup always runs, - // even if detect/install/query fails. let resolve_inner = || -> Result, RuntimeError> { let pkg_mgr = detect_package_manager(&sandbox.overlay_merged) .or_else(|| detect_package_manager(&rootfs)) @@ -113,13 +106,11 @@ impl RuntimeBackend for NamespaceBackend { let result = resolve_inner(); - // Always cleanup: unmount overlay and remove temp directory let _ = unmount_overlay(&sandbox); let _ = std::fs::remove_dir_all(&tmp_env); let versions = result?; - // Map back to ResolvedPackage, falling back to "unresolved" if query failed spec.manifest .system_packages .iter() @@ -150,21 +141,17 @@ impl RuntimeBackend for NamespaceBackend { eprintln!("[karapace] {msg}"); }; - // Resolve and download the base image let resolved = resolve_image(&spec.manifest.base_image)?; let image_cache = ImageCache::new(&self.store_root); let rootfs = image_cache.ensure_image(&resolved, &progress, spec.offline)?; - // Set up overlay filesystem let mut sandbox = SandboxConfig::new(rootfs.clone(), &spec.env_id, &env_dir); sandbox.isolate_network = spec.offline || spec.manifest.network_isolation; mount_overlay(&sandbox)?; - // Set up container rootfs (create dirs, user, etc.) setup_container_rootfs(&sandbox)?; - // Install system packages if any if !spec.manifest.system_packages.is_empty() { if spec.offline { return Err(RuntimeError::ExecFailed( @@ -192,10 +179,8 @@ impl RuntimeBackend for NamespaceBackend { progress("packages installed"); } - // Unmount overlay after build (will be re-mounted on enter) unmount_overlay(&sandbox)?; - // Write state marker std::fs::write(env_dir.join(".built"), "1")?; progress(&format!( @@ -216,7 +201,6 @@ impl RuntimeBackend for NamespaceBackend { ))); } - // Resolve image to get rootfs path let resolved = resolve_image(&spec.manifest.base_image)?; let image_cache = ImageCache::new(&self.store_root); let rootfs = image_cache.rootfs_path(&resolved.cache_key); @@ -227,21 +211,17 @@ impl RuntimeBackend for NamespaceBackend { )); } - // Create sandbox config let mut sandbox = SandboxConfig::new(rootfs, &spec.env_id, &env_dir); sandbox.isolate_network = spec.offline || spec.manifest.network_isolation; sandbox.hostname = format!("karapace-{}", &spec.env_id[..12.min(spec.env_id.len())]); - // Compute host integration (Wayland, PipeWire, GPU, etc.) let host = compute_host_integration(&spec.manifest); sandbox.bind_mounts.extend(host.bind_mounts); sandbox.env_vars.extend(host.env_vars); - // Mount overlay mount_overlay(&sandbox)?; setup_container_rootfs(&sandbox)?; - // Emit terminal markers terminal::emit_container_push(&spec.env_id, &sandbox.hostname); terminal::print_container_banner( &spec.env_id, @@ -249,7 +229,6 @@ impl RuntimeBackend for NamespaceBackend { &sandbox.hostname, ); - // Spawn the sandbox so we can record the host PID for `stop`. let mut child = match spawn_enter_interactive(&sandbox) { Ok(c) => c, Err(e) => { diff --git a/crates/karapace-store/src/wal.rs b/crates/karapace-store/src/wal.rs index 4dd2068..087db6a 100644 --- a/crates/karapace-store/src/wal.rs +++ b/crates/karapace-store/src/wal.rs @@ -19,21 +19,16 @@ fn parse_env_state(s: &str) -> Option { } } -/// A single rollback step that can undo part of an operation. #[derive(Debug, Clone, Serialize, Deserialize)] pub enum RollbackStep { - /// Remove a directory tree (e.g. orphaned env_dir). RemoveDir(PathBuf), - /// Remove a single file (e.g. metadata, layer manifest). RemoveFile(PathBuf), - /// Reset an environment's metadata state (e.g. Running → Built after crash). ResetState { env_id: String, target_state: String, }, } -/// The type of mutating operation being tracked. #[derive(Debug, Clone, Serialize, Deserialize)] pub enum WalOpKind { Build, @@ -61,7 +56,6 @@ impl std::fmt::Display for WalOpKind { } } -/// A WAL entry representing an in-flight operation. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct WalEntry { pub op_id: String, @@ -71,11 +65,6 @@ pub struct WalEntry { pub rollback_steps: Vec, } -/// Write-ahead log for crash recovery. -/// -/// Mutating engine methods create a WAL entry before starting work, -/// append rollback steps as side effects occur, and remove the entry -/// on successful completion. On startup, incomplete entries are rolled back. pub struct WriteAheadLog { wal_dir: PathBuf, } @@ -86,13 +75,11 @@ impl WriteAheadLog { Self { wal_dir } } - /// Ensure the WAL directory exists. pub fn initialize(&self) -> Result<(), StoreError> { fs::create_dir_all(&self.wal_dir)?; Ok(()) } - /// Begin a new WAL entry for an operation. Returns the op_id. pub fn begin(&self, kind: WalOpKind, env_id: &str) -> Result { let op_id = format!( "{}-{}", @@ -111,7 +98,6 @@ impl WriteAheadLog { Ok(op_id) } - /// Append a rollback step to an existing WAL entry. pub fn add_rollback_step(&self, op_id: &str, step: RollbackStep) -> Result<(), StoreError> { let mut entry = self.read_entry(op_id)?; entry.rollback_steps.push(step); @@ -119,7 +105,6 @@ impl WriteAheadLog { Ok(()) } - /// Commit (remove) a WAL entry after successful completion. pub fn commit(&self, op_id: &str) -> Result<(), StoreError> { let path = self.entry_path(op_id); if path.exists() { @@ -129,7 +114,6 @@ impl WriteAheadLog { Ok(()) } - /// List all incomplete WAL entries. pub fn list_incomplete(&self) -> Result, StoreError> { if !self.wal_dir.exists() { return Ok(Vec::new()); @@ -144,7 +128,6 @@ impl WriteAheadLog { Ok(entry) => entries.push(entry), Err(e) => { warn!("corrupt WAL entry {}: {e}", path.display()); - // Remove corrupt entries let _ = fs::remove_file(&path); } }, @@ -159,8 +142,6 @@ impl WriteAheadLog { Ok(entries) } - /// Roll back all incomplete WAL entries. - /// Returns the number of entries rolled back. pub fn recover(&self) -> Result { let entries = self.list_incomplete()?; let count = entries.len(); @@ -170,7 +151,6 @@ impl WriteAheadLog { entry.kind, entry.env_id, entry.op_id ); self.rollback_entry(entry); - // Remove the WAL entry after rollback let _ = fs::remove_file(self.entry_path(&entry.op_id)); } if count > 0 { @@ -180,7 +160,6 @@ impl WriteAheadLog { } fn rollback_entry(&self, entry: &WalEntry) { - // Execute rollback steps in reverse order for step in entry.rollback_steps.iter().rev() { match step { RollbackStep::RemoveDir(path) => { @@ -213,7 +192,6 @@ impl WriteAheadLog { continue; }; - // wal_dir = /store/wal let Some(store_dir) = self.wal_dir.parent() else { continue; };