From ce11f03fe63b458c38c331e1c0441b3967b44fc5 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Thu, 21 Aug 2025 21:28:35 +0200 Subject: [PATCH] radicle/profile: Control socket path for Windows The `winpipe` crate which is our current best bet for support on Windows requires that named pipes are at the magical location `\\.pipe\`. Provide a default on Windows that matches this, and use our freshly assigned IANA service name for it. This is a breaking change, as we remove a `pub const`, it should be reasonably easy to fix by dependents, and probably it was a mistake to make the default `pub const` as dependents should call `Home::socket` anyway. --- crates/radicle/CHANGELOG.md | 24 ++++++++++++++++++++++++ crates/radicle/src/node.rs | 2 -- crates/radicle/src/profile.rs | 29 ++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 crates/radicle/CHANGELOG.md diff --git a/crates/radicle/CHANGELOG.md b/crates/radicle/CHANGELOG.md new file mode 100644 index 00000000..4fbd1d7d --- /dev/null +++ b/crates/radicle/CHANGELOG.md @@ -0,0 +1,24 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +### Changed + +- `radicle::profile::Home::socket` defaults to the path `\\.\pipe\radicle-node` + on Windows. The behavior on Unix-like systems has *not* changed. + +### Deprecated + +### Removed + +- `radicle::node::DEFAULT_SOCKET_NAME`, use `radicle::profile::Home::socket` + instead. + +### Security diff --git a/crates/radicle/src/node.rs b/crates/radicle/src/node.rs index 8753d9e9..41cd433b 100644 --- a/crates/radicle/src/node.rs +++ b/crates/radicle/src/node.rs @@ -53,8 +53,6 @@ pub use timestamp::Timestamp; /// Peer-to-peer protocol version. pub const PROTOCOL_VERSION: u8 = 1; -/// Default name for control socket file. -pub const DEFAULT_SOCKET_NAME: &str = "control.sock"; /// Default radicle protocol port. pub const DEFAULT_PORT: u16 = 8776; /// Default timeout when waiting for the node to respond with data. diff --git a/crates/radicle/src/profile.rs b/crates/radicle/src/profile.rs index 4ae3a66e..68f936c2 100644 --- a/crates/radicle/src/profile.rs +++ b/crates/radicle/src/profile.rs @@ -578,9 +578,32 @@ impl Home { } pub fn socket(&self) -> PathBuf { - env::var_os(env::RAD_SOCKET) - .map(PathBuf::from) - .unwrap_or_else(|| self.node().join(node::DEFAULT_SOCKET_NAME)) + use env::RAD_SOCKET; + + #[cfg(unix)] + const DEFAULT_SOCKET_NAME: &str = "control.sock"; + + #[cfg(windows)] + const DEFAULT_SOCKET_NAME: &str = r#"\\.\pipe\radicle-node"#; + + match env::var_os(RAD_SOCKET).map(PathBuf::from) { + None => { + #[cfg(unix)] + return self.node().join(DEFAULT_SOCKET_NAME); + + #[cfg(windows)] + return PathBuf::from(DEFAULT_SOCKET_NAME); + } + Some(path) => { + #[cfg(windows)] + { + const PIPE_PREFIX: &str = r#"\\.\pipe\"#; + assert!(path.starts_with(PIPE_PREFIX), "The value of the environment variable {RAD_SOCKET} ('{}') must start with {PIPE_PREFIX}. This restriction might be relaxed in the future.", path.display()); + } + + path + } + } } /// Return a read-write handle to the notifications database.