diff --git a/crates/kiri-win/src/engine.rs b/crates/kiri-win/src/engine.rs index 6d7ecc25f..f39277b9a 100644 --- a/crates/kiri-win/src/engine.rs +++ b/crates/kiri-win/src/engine.rs @@ -926,7 +926,7 @@ fn about() { } fn npipe_host(pipe: &str) -> String { - format!("npipe:{}", pipe.replace('\\', "/")) + crate::dockerctx::npipe_host(pipe) } fn context_meta(dir: &std::path::Path, name: &str) -> std::path::PathBuf { diff --git a/crates/kiri/src/dockerctx.rs b/crates/kiri/src/dockerctx.rs index 379b91227..bd96d87cd 100644 --- a/crates/kiri/src/dockerctx.rs +++ b/crates/kiri/src/dockerctx.rs @@ -182,6 +182,13 @@ pub fn sock_at(path: &Path, ours: &Path, engines: &[PathBuf]) -> Endpoint { Endpoint::Taken(path.display().to_string()) } +/// Formats a Windows named pipe (`\\.\pipe\kiri`) as a four-slash Docker +/// context endpoint (`npipe:////./pipe/kiri`). +#[cfg_attr(not(any(windows, test)), allow(dead_code))] +pub fn npipe_host(pipe: &str) -> String { + format!("npipe:////{}", pipe.replace('\\', "/").trim_start_matches('/')) +} + /// docker's config folder: DOCKER_CONFIG, else `.docker` in the home /// folder (HOME, or USERPROFILE on Windows). pub fn docker_dir() -> Option { @@ -414,12 +421,19 @@ pub fn repair_windows_config(dir: &Path, opts: WindowsRepairOpts<'_>) -> io::Res let mut out = WindowsRepair::default(); let meta = context_meta(dir, opts.ours); let meta_file = meta.join("meta.json"); - let unix_host_on_npipe = opts.host.starts_with("npipe:") + let stale_host_on_npipe = opts.host.starts_with("npipe:") && read_json(&meta_file) .ok() - .and_then(|v| v["Endpoints"]["docker"]["Host"].as_str().map(|h| h.starts_with("unix:"))) + .and_then(|v| { + v["Endpoints"]["docker"]["Host"].as_str().map(|h| { + h.starts_with("unix:") + || (h.get(..8).is_some_and(|s| s.eq_ignore_ascii_case("npipe://")) + && !h.starts_with("npipe:////") + && same_host(h, opts.host)) + }) + }) .unwrap_or(false); - if opts.force_context_write || !meta_file.is_file() || unix_host_on_npipe { + if opts.force_context_write || !meta_file.is_file() || stale_host_on_npipe { write_context(&meta, opts.ours, opts.description, opts.host)?; out.context_written = true; } @@ -805,6 +819,49 @@ mod tests { let healed = read_json(&context_meta(&docker, "kiri").join("meta.json")).unwrap(); assert_eq!(healed["Endpoints"]["docker"]["Host"], "npipe:////./pipe/kiri"); + // 2c. A two-slash `npipe://./pipe/kiri` written by an earlier build is self-healed + // to four-slash `npipe:////./pipe/kiri`, while a custom pipe (`kiri-2`) stays. + write_context(&context_meta(&docker, "kiri"), "kiri", "Kiri (WSL2)", "npipe://./pipe/kiri").unwrap(); + let r_2slash = repair_windows_config( + &docker, + WindowsRepairOpts { + ours: "kiri", + description: "Kiri (WSL2)", + host: "npipe:////./pipe/kiri", + plugins_dir: Some(&plugins), + force_context_write: false, + set_current_if_empty: false, + force_use: false, + desktop_installed: false, + }, + ) + .unwrap(); + assert!(r_2slash.context_written); + assert_eq!( + read_json(&context_meta(&docker, "kiri").join("meta.json")).unwrap()["Endpoints"]["docker"]["Host"], + "npipe:////./pipe/kiri" + ); + write_context(&context_meta(&docker, "kiri"), "kiri", "Kiri (WSL2)", "npipe:////./pipe/kiri-2").unwrap(); + let r_other = repair_windows_config( + &docker, + WindowsRepairOpts { + ours: "kiri", + description: "Kiri (WSL2)", + host: "npipe:////./pipe/kiri", + plugins_dir: Some(&plugins), + force_context_write: false, + set_current_if_empty: false, + force_use: false, + desktop_installed: false, + }, + ) + .unwrap(); + assert!(!r_other.context_written); + assert_eq!( + read_json(&context_meta(&docker, "kiri").join("meta.json")).unwrap()["Endpoints"]["docker"]["Host"], + "npipe:////./pipe/kiri-2" + ); + // 3. Corrupt config.json is never overwritten. std::fs::write(docker.join("config.json"), "{broken").unwrap(); assert_eq!( diff --git a/crates/kiri/src/import.rs b/crates/kiri/src/import.rs index 097f16606..13724d15a 100644 --- a/crates/kiri/src/import.rs +++ b/crates/kiri/src/import.rs @@ -1771,7 +1771,7 @@ fn ensure_windows_kiri_context() { let plugins = crate::dockerctx::find_windows_cli_plugins(exe.as_deref(), local.as_deref()); let desktop = std::env::var_os("ProgramFiles") .is_some_and(|p| std::path::Path::new(&p).join(r"Docker\Docker\Docker Desktop.exe").is_file()); - let host = format!("npipe:{}", client::pipe().replace('\\', "/")); + let host = crate::dockerctx::npipe_host(&client::pipe()); let _ = crate::dockerctx::repair_windows_config( &dir, crate::dockerctx::WindowsRepairOpts { diff --git a/crates/kiri/src/setup_win.rs b/crates/kiri/src/setup_win.rs index 70b1b566e..75a56763c 100644 --- a/crates/kiri/src/setup_win.rs +++ b/crates/kiri/src/setup_win.rs @@ -17,7 +17,7 @@ use crate::dockerctx::{ const USAGE: &str = "usage: kiri setup [--use]"; fn npipe_host(pipe: &str) -> String { - format!("npipe:////{}", pipe.replace('\\', "/").trim_start_matches('/')) + crate::dockerctx::npipe_host(pipe) } /// Best-effort background self-heal of `%USERPROFILE%\.docker\config.json` and diff --git a/docs/fix-registry.md b/docs/fix-registry.md index 2b34b8684..3c2bf7984 100644 --- a/docs/fix-registry.md +++ b/docs/fix-registry.md @@ -13,6 +13,12 @@ A log of every merged bug fix in Kiri, newest first, together with any later bug ## Fixes +### #984 Windows: format `npipe:////` context URLs with four slashes in `kiri-win` and `kiri import` and self-heal two-slash `npipe://./pipe/` contexts (unreleased) +- Fixes: #984 (`kiri-win/src/engine.rs` and `import.rs` formatted `\\.\pipe\kiri` as `npipe://./pipe/kiri` with two slashes instead of `npipe:////./pipe/kiri`, and `repair_windows_config` did not upgrade existing two-slash `npipe://./pipe/kiri` context endpoints on `kiri update ` or startup) +- Caused: none known +- Caused by: #988 +- Check: `crates/kiri-win/src/engine.rs`, `crates/kiri/src/dockerctx.rs`, `crates/kiri/src/setup_win.rs` + ### #381, #382, #420, #984 macOS, Networking & Windows/WSL: preserve virtiofs `chown` across host fsnotify events, attach secondary networks before PID 1 execs, format `npipe:////` context URLs with four slashes, and preserve WSL virtual/cgroup binds and local bind volumes (unreleased) - Fixes: #382 (`kiri_inject.c` called `__d_drop` on `C`/`M`/`A` host fsnotify events, evicting `struct fuse_inode` and losing in-memory `chown_uid`/`chown_gid` on macOS bind mounts when `FSEvents` echoed container writes), #381 (`start_on_vm` spawned the container process before attaching `spec.extra_networks`, causing fast `docker compose run` commands on secondary external networks to run before `eth1` and its IPv4 default route were attached), #984 (`setup_win::npipe_host` formatted `\\.\pipe\kiri` with two slashes `npipe://./pipe/kiri` instead of four `npipe:////./pipe/kiri`), #420 / #358 (WSL distro bind translation rewrote `/run/host-services/ssh-auth.sock` and `/sys` paths into `/mnt/wsl/kiri/roots//...` and `POST /volumes/create` did not resolve local `o=bind` volume `device` paths relative to the calling WSL distro or Windows drive) - Caused: none known