Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/kiri-win/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
63 changes: 60 additions & 3 deletions crates/kiri/src/dockerctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion crates/kiri/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/kiri/src/setup_win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/fix-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <container>` 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/<distro>/...` 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
Expand Down
Loading