From 9d964fe4264d688598deb4f58b004d15a553374a Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 16:24:23 +0200 Subject: [PATCH 01/12] chore(deps): update to interprocess 2 --- crates/transport-ipc/Cargo.toml | 2 +- crates/transport-ipc/src/connect.rs | 18 ++++++---- crates/transport-ipc/src/lib.rs | 54 ++++++++++------------------- crates/transport-ipc/src/mock.rs | 13 ++++--- 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/crates/transport-ipc/Cargo.toml b/crates/transport-ipc/Cargo.toml index 7ead7246861..fd4ee3aa2d5 100644 --- a/crates/transport-ipc/Cargo.toml +++ b/crates/transport-ipc/Cargo.toml @@ -24,7 +24,7 @@ tokio-util = { workspace = true, features = ["io", "compat"] } tracing.workspace = true bytes = "1.5.0" -interprocess = { version = "1.2.1", features = ["tokio", "tokio_support"] } +interprocess = { version = "2", features = ["tokio"] } serde = { workspace = true, optional = true } tempfile = { workspace = true, optional = true } diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index ad3c55cf6a4..beacd0850e5 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -1,3 +1,4 @@ +use interprocess::local_socket::{GenericFilePath, ToFsName}; use std::{ ffi::{CString, OsString}, path::PathBuf, @@ -21,7 +22,7 @@ impl IpcConnect { } macro_rules! impl_connect { - ($target:ty) => { + ($target:ty => $map:ident) => { impl From<$target> for IpcConnect<$target> { fn from(inner: $target) -> Self { Self { inner } @@ -42,7 +43,12 @@ macro_rules! impl_connect { async fn connect( &self, ) -> Result { - crate::IpcBackend::connect(&self.inner) + let name = self + .inner + .$map() + .to_fs_name::() + .map_err(alloy_transport::TransportErrorKind::custom)?; + crate::IpcBackend::connect(name) .await .map_err(alloy_transport::TransportErrorKind::custom) } @@ -50,7 +56,7 @@ macro_rules! impl_connect { }; } -impl_connect!(OsString); -impl_connect!(CString); -impl_connect!(PathBuf); -impl_connect!(String); +impl_connect!(OsString => as_os_str); +impl_connect!(CString => as_c_str); +impl_connect!(PathBuf => as_path); +impl_connect!(String => as_str); diff --git a/crates/transport-ipc/src/lib.rs b/crates/transport-ipc/src/lib.rs index bf3d3561e55..e03696af4f6 100644 --- a/crates/transport-ipc/src/lib.rs +++ b/crates/transport-ipc/src/lib.rs @@ -19,11 +19,14 @@ extern crate tracing; use bytes::{Buf, BytesMut}; -use futures::{ready, AsyncRead, AsyncWriteExt, StreamExt}; -use interprocess::local_socket::{tokio::LocalSocketStream, ToLocalSocketName}; +use futures::{ready, StreamExt}; +use interprocess::local_socket::{tokio::prelude::*, Name}; use std::task::Poll::Ready; -use tokio::select; -use tokio_util::compat::FuturesAsyncReadCompatExt; +use tokio::{ + io::{AsyncRead, AsyncWriteExt}, + select, +}; +use tokio_util::io::poll_read_buf; mod connect; pub use connect::IpcConnect; @@ -37,31 +40,24 @@ type Result = std::result::Result; /// An IPC backend task. struct IpcBackend { - pub(crate) socket: LocalSocketStream, + pub(crate) stream: LocalSocketStream, pub(crate) interface: alloy_pubsub::ConnectionInterface, } impl IpcBackend { /// Connect to a local socket. Either a unix socket or a windows named pipe. - async fn connect<'a, I>(name: &I) -> Result - where - // TODO: remove bound on next interprocess crate release - I: ToLocalSocketName<'a> + Clone, - { - let socket = LocalSocketStream::connect(name.clone()).await?; + async fn connect(name: Name<'_>) -> Result { + let stream = LocalSocketStream::connect(name).await?; let (handle, interface) = alloy_pubsub::ConnectionHandle::new(); - - let backend = IpcBackend { socket, interface }; - + let backend = IpcBackend { stream, interface }; backend.spawn(); - Ok(handle) } fn spawn(mut self) { let fut = async move { - let (read, mut writer) = self.socket.into_split(); + let (read, mut writer) = self.stream.split(); let mut read = ReadJsonStream::new(read).fuse(); let err = loop { @@ -118,43 +114,32 @@ const CAPACITY: usize = 4096; pub struct ReadJsonStream { /// The underlying reader. #[pin] - reader: tokio_util::compat::Compat, + reader: T, /// A buffer for reading data from the reader. buf: BytesMut, /// Whether the buffer has been drained. drained: bool, } -impl ReadJsonStream -where - T: AsyncRead, -{ +impl ReadJsonStream { fn new(reader: T) -> Self { - Self { reader: reader.compat(), buf: BytesMut::with_capacity(CAPACITY), drained: true } + Self { reader, buf: BytesMut::with_capacity(CAPACITY), drained: true } } } -impl From for ReadJsonStream -where - T: AsyncRead, -{ +impl From for ReadJsonStream { fn from(reader: T) -> Self { Self::new(reader) } } -impl futures::stream::Stream for ReadJsonStream -where - T: AsyncRead, -{ +impl futures::stream::Stream for ReadJsonStream { type Item = alloy_json_rpc::PubSubItem; fn poll_next( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { - use tokio_util::io::poll_read_buf; - let mut this = self.project(); loop { @@ -235,7 +220,6 @@ where mod tests { use super::*; use std::future::poll_fn; - use tokio_util::compat::TokioAsyncReadCompatExt; #[tokio::test] async fn test_partial_stream() { @@ -248,7 +232,7 @@ mod tests { .read(r#", "params": {"subscription": "0xcd0c3e8af590364c09d0fa6a1210faf5", "result": {"difficulty": "0xd9263f42a87", "uncles": []}} }"#.as_bytes()) .build(); - let mut reader = ReadJsonStream::new(mock.compat()); + let mut reader = ReadJsonStream::new(mock); poll_fn(|cx| { let res = reader.poll_next_unpin(cx); assert!(res.is_pending()); @@ -269,7 +253,7 @@ mod tests { .read(vec![b'a'; CAPACITY].as_ref()) .build(); - let mut reader = ReadJsonStream::new(mock.compat()); + let mut reader = ReadJsonStream::new(mock); poll_fn(|cx| { let res = reader.poll_next_unpin(cx); assert!(res.is_pending()); diff --git a/crates/transport-ipc/src/mock.rs b/crates/transport-ipc/src/mock.rs index 9c3a8947c33..0700129d089 100644 --- a/crates/transport-ipc/src/mock.rs +++ b/crates/transport-ipc/src/mock.rs @@ -1,10 +1,11 @@ //! Mock IPC server. use alloy_json_rpc::Response; -use futures::{AsyncReadExt, AsyncWriteExt}; +use interprocess::local_socket::{tokio::prelude::*, GenericFilePath}; use serde::Serialize; use std::{collections::VecDeque, path::PathBuf}; use tempfile::NamedTempFile; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; /// Mock IPC server. /// @@ -71,13 +72,11 @@ impl MockIpcServer { /// Run the server. pub async fn spawn(mut self) { tokio::spawn(async move { - let socket = interprocess::local_socket::tokio::LocalSocketStream::connect( - self.path.into_temp_path().to_path_buf(), - ) - .await - .unwrap(); + let tmp = self.path.into_temp_path(); + let name = tmp.to_fs_name::().unwrap(); + let socket = LocalSocketStream::connect(name).await.unwrap(); - let (mut reader, mut writer) = socket.into_split(); + let (mut reader, mut writer) = socket.split(); let mut buf = [0u8; 4096]; loop { From 2c71bd7364ed33c60333ca562e77b30dae3c962e Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 16:54:35 +0200 Subject: [PATCH 02/12] cfg --- crates/transport-ipc/src/connect.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index beacd0850e5..bdf14ff8527 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -57,6 +57,7 @@ macro_rules! impl_connect { } impl_connect!(OsString => as_os_str); +#[cfg(unix)] impl_connect!(CString => as_c_str); impl_connect!(PathBuf => as_path); impl_connect!(String => as_str); From eb0e954adca09432e68c5f5bc452d47ba096942c Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 17:14:50 +0200 Subject: [PATCH 03/12] try --- crates/node-bindings/src/geth.rs | 16 ++++++++-------- crates/rpc-client/tests/it/ipc.rs | 5 ++--- crates/transport-ipc/src/connect.rs | 9 +++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/node-bindings/src/geth.rs b/crates/node-bindings/src/geth.rs index 6bbf44e60b3..835866b88d2 100644 --- a/crates/node-bindings/src/geth.rs +++ b/crates/node-bindings/src/geth.rs @@ -327,14 +327,14 @@ impl Geth { /// This will put the geth instance into non-dev mode, discarding any previously set dev-mode /// options. pub fn p2p_port(mut self, port: u16) -> Self { - match self.mode { + match &mut self.mode { GethMode::Dev(_) => { self.mode = GethMode::NonDev(PrivateNetOptions { p2p_port: Some(port), ..Default::default() }) } - GethMode::NonDev(ref mut opts) => opts.p2p_port = Some(port), + GethMode::NonDev(opts) => opts.p2p_port = Some(port), } self } @@ -376,12 +376,12 @@ impl Geth { } fn inner_disable_discovery(&mut self) { - match self.mode { + match &mut self.mode { GethMode::Dev(_) => { self.mode = GethMode::NonDev(PrivateNetOptions { discovery: false, ..Default::default() }) } - GethMode::NonDev(ref mut opts) => opts.discovery = false, + GethMode::NonDev(opts) => opts.discovery = false, } } @@ -506,7 +506,7 @@ impl Geth { cmd.arg("--miner.etherbase").arg(format!("{clique_addr:?}")); } - if let Some(ref genesis) = self.genesis { + if let Some(genesis) = &self.genesis { // create a temp dir to store the genesis file let temp_genesis_dir_path = tempdir().map_err(GethError::CreateDirError)?.into_path(); @@ -524,7 +524,7 @@ impl Geth { })?; let mut init_cmd = Command::new(bin_path); - if let Some(ref data_dir) = self.data_dir { + if let Some(data_dir) = &self.data_dir { init_cmd.arg("--datadir").arg(data_dir); } @@ -548,7 +548,7 @@ impl Geth { })?; } - if let Some(ref data_dir) = self.data_dir { + if let Some(data_dir) = &self.data_dir { cmd.arg("--datadir").arg(data_dir); // create the directory if it doesn't exist @@ -586,7 +586,7 @@ impl Geth { // debug verbosity is needed to check when peers are added cmd.arg("--verbosity").arg("4"); - if let Some(ref ipc) = self.ipc_path { + if let Some(ipc) = &self.ipc_path { cmd.arg("--ipcpath").arg(ipc); } diff --git a/crates/rpc-client/tests/it/ipc.rs b/crates/rpc-client/tests/it/ipc.rs index d5ba46c3d5b..bd13520455a 100644 --- a/crates/rpc-client/tests/it/ipc.rs +++ b/crates/rpc-client/tests/it/ipc.rs @@ -2,7 +2,6 @@ use alloy_node_bindings::Geth; use alloy_primitives::U64; use alloy_rpc_client::{ClientBuilder, RpcCall}; use alloy_transport_ipc::IpcConnect; -use std::path::PathBuf; #[tokio::test] async fn it_makes_a_request() { @@ -15,8 +14,8 @@ async fn it_makes_a_request() { .data_dir(temp_dir.path()) .spawn(); - let connector: IpcConnect<_> = PathBuf::from(geth.ipc_endpoint()).into(); - let client = ClientBuilder::default().pubsub(connector).await.unwrap(); + let connect = IpcConnect::new(geth.ipc_endpoint()); + let client = ClientBuilder::default().pubsub(connect).await.unwrap(); let req: RpcCall<_, (), U64> = client.request("eth_blockNumber", ()); let timeout = tokio::time::timeout(std::time::Duration::from_secs(2), req); diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index bdf14ff8527..d45a14a49b8 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -1,9 +1,14 @@ -use interprocess::local_socket::{GenericFilePath, ToFsName}; +use interprocess::local_socket::ToFsName; use std::{ ffi::{CString, OsString}, path::PathBuf, }; +#[cfg(unix)] +type FsName = interprocess::local_socket::GenericFilePath; +#[cfg(windows)] +type FsName = interprocess::local_socket::GenericNamespaced; + /// An IPC Connection object. #[derive(Clone, Debug)] pub struct IpcConnect { @@ -46,7 +51,7 @@ macro_rules! impl_connect { let name = self .inner .$map() - .to_fs_name::() + .to_fs_name::() .map_err(alloy_transport::TransportErrorKind::custom)?; crate::IpcBackend::connect(name) .await From 2118f651dcacd1e54611d99e087ae9f36106d598 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 17:42:24 +0200 Subject: [PATCH 04/12] try2 --- crates/node-bindings/src/geth.rs | 2 +- crates/transport-ipc/src/connect.rs | 39 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/node-bindings/src/geth.rs b/crates/node-bindings/src/geth.rs index 835866b88d2..cc521f8f678 100644 --- a/crates/node-bindings/src/geth.rs +++ b/crates/node-bindings/src/geth.rs @@ -385,7 +385,7 @@ impl Geth { } } - /// Manually sets the IPC path for the socket manually. + /// Sets the IPC path for the socket. pub fn ipc_path>(mut self, path: T) -> Self { self.ipc_path = Some(path.into()); self diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index d45a14a49b8..e3dd83b1b0b 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -1,13 +1,23 @@ -use interprocess::local_socket::ToFsName; -use std::{ - ffi::{CString, OsString}, - path::PathBuf, -}; +use interprocess::local_socket as ls; +use std::io; #[cfg(unix)] -type FsName = interprocess::local_socket::GenericFilePath; +fn to_name<'a, S>(path: impl ls::ToFsName<'a, S>) -> io::Result> +where + S: ToOwned + ?Sized, + ls::GenericFilePath: ls::PathNameType, +{ + path.to_fs_name::() +} + #[cfg(windows)] -type FsName = interprocess::local_socket::GenericNamespaced; +fn to_name<'a, S>(path: impl ls::ToNsName<'a, S>) -> io::Result> +where + S: ToOwned + ?Sized, + ls::GenericNamespaced: ls::NamespacedNameType, +{ + path.to_ns_name::() +} /// An IPC Connection object. #[derive(Clone, Debug)] @@ -27,7 +37,7 @@ impl IpcConnect { } macro_rules! impl_connect { - ($target:ty => $map:ident) => { + ($target:ty => $($map:tt)*) => { impl From<$target> for IpcConnect<$target> { fn from(inner: $target) -> Self { Self { inner } @@ -48,10 +58,7 @@ macro_rules! impl_connect { async fn connect( &self, ) -> Result { - let name = self - .inner - .$map() - .to_fs_name::() + let name = to_name(self.inner $($map)*) .map_err(alloy_transport::TransportErrorKind::custom)?; crate::IpcBackend::connect(name) .await @@ -61,8 +68,8 @@ macro_rules! impl_connect { }; } -impl_connect!(OsString => as_os_str); +impl_connect!(std::ffi::OsString => .as_os_str()); #[cfg(unix)] -impl_connect!(CString => as_c_str); -impl_connect!(PathBuf => as_path); -impl_connect!(String => as_str); +impl_connect!(std::ffi::CString => .as_c_str()); +impl_connect!(std::path::PathBuf => .as_os_str()); +impl_connect!(String => .as_str()); From b7094604d6b68cfee54cc7a190773ca3a1608fd2 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 17:47:29 +0200 Subject: [PATCH 05/12] fixmock --- crates/transport-ipc/src/connect.rs | 4 ++-- crates/transport-ipc/src/mock.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index e3dd83b1b0b..a8e35c4e725 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -2,7 +2,7 @@ use interprocess::local_socket as ls; use std::io; #[cfg(unix)] -fn to_name<'a, S>(path: impl ls::ToFsName<'a, S>) -> io::Result> +pub(crate) fn to_name<'a, S>(path: impl ls::ToFsName<'a, S>) -> io::Result> where S: ToOwned + ?Sized, ls::GenericFilePath: ls::PathNameType, @@ -11,7 +11,7 @@ where } #[cfg(windows)] -fn to_name<'a, S>(path: impl ls::ToNsName<'a, S>) -> io::Result> +pub(crate) fn to_name<'a, S>(path: impl ls::ToNsName<'a, S>) -> io::Result> where S: ToOwned + ?Sized, ls::GenericNamespaced: ls::NamespacedNameType, diff --git a/crates/transport-ipc/src/mock.rs b/crates/transport-ipc/src/mock.rs index 0700129d089..b2cb7f49074 100644 --- a/crates/transport-ipc/src/mock.rs +++ b/crates/transport-ipc/src/mock.rs @@ -1,7 +1,7 @@ //! Mock IPC server. use alloy_json_rpc::Response; -use interprocess::local_socket::{tokio::prelude::*, GenericFilePath}; +use interprocess::local_socket::tokio::prelude::*; use serde::Serialize; use std::{collections::VecDeque, path::PathBuf}; use tempfile::NamedTempFile; @@ -73,7 +73,7 @@ impl MockIpcServer { pub async fn spawn(mut self) { tokio::spawn(async move { let tmp = self.path.into_temp_path(); - let name = tmp.to_fs_name::().unwrap(); + let name = crate::connect::to_name(&*tmp).unwrap(); let socket = LocalSocketStream::connect(name).await.unwrap(); let (mut reader, mut writer) = socket.split(); From 7795788a69be2ae7d689b41ca541dc16f1072a18 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 17:48:31 +0200 Subject: [PATCH 06/12] deny --- deny.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/deny.toml b/deny.toml index a916dc7f954..7d08a363263 100644 --- a/deny.toml +++ b/deny.toml @@ -20,6 +20,7 @@ allow = [ "Apache-2.0", "Apache-2.0 WITH LLVM-exception", "BSD-3-Clause", + "0BSD", "ISC", "Unicode-DFS-2016", "Unlicense", From 2e42a6ea0da1f88d60c5c74a3d0ea147b338a36d Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 17:53:34 +0200 Subject: [PATCH 07/12] win --- crates/transport-ipc/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/transport-ipc/src/mock.rs b/crates/transport-ipc/src/mock.rs index b2cb7f49074..4ac2f7fcbd9 100644 --- a/crates/transport-ipc/src/mock.rs +++ b/crates/transport-ipc/src/mock.rs @@ -73,7 +73,7 @@ impl MockIpcServer { pub async fn spawn(mut self) { tokio::spawn(async move { let tmp = self.path.into_temp_path(); - let name = crate::connect::to_name(&*tmp).unwrap(); + let name = crate::connect::to_name(tmp.as_os_str()).unwrap(); let socket = LocalSocketStream::connect(name).await.unwrap(); let (mut reader, mut writer) = socket.split(); From 40ca7ff080cadab990c190d302d458a3b481d85c Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 18:12:48 +0200 Subject: [PATCH 08/12] re --- crates/transport-ipc/src/connect.rs | 44 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index a8e35c4e725..5cb2d6c4415 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -1,22 +1,15 @@ use interprocess::local_socket as ls; use std::io; -#[cfg(unix)] -pub(crate) fn to_name<'a, S>(path: impl ls::ToFsName<'a, S>) -> io::Result> -where - S: ToOwned + ?Sized, - ls::GenericFilePath: ls::PathNameType, -{ - path.to_fs_name::() -} - -#[cfg(windows)] -pub(crate) fn to_name<'a, S>(path: impl ls::ToNsName<'a, S>) -> io::Result> -where - S: ToOwned + ?Sized, - ls::GenericNamespaced: ls::NamespacedNameType, -{ - path.to_ns_name::() +pub(crate) fn to_name(mut path: &std::ffi::OsStr) -> io::Result> { + if cfg!(windows) { + if let Some(name) = path.as_encoded_bytes().strip_prefix(br"\\.\pipe\") { + path = unsafe { std::ffi::OsStr::from_encoded_bytes_unchecked(name) } + } + ls::ToNsName::to_ns_name::(path) + } else { + ls::ToFsName::to_fs_name::(path) + } } /// An IPC Connection object. @@ -37,7 +30,7 @@ impl IpcConnect { } macro_rules! impl_connect { - ($target:ty => $($map:tt)*) => { + ($target:ty => | $inner:ident | $map:expr) => { impl From<$target> for IpcConnect<$target> { fn from(inner: $target) -> Self { Self { inner } @@ -58,8 +51,9 @@ macro_rules! impl_connect { async fn connect( &self, ) -> Result { - let name = to_name(self.inner $($map)*) - .map_err(alloy_transport::TransportErrorKind::custom)?; + let $inner = &self.inner; + let inner = $map; + let name = to_name(inner).map_err(alloy_transport::TransportErrorKind::custom)?; crate::IpcBackend::connect(name) .await .map_err(alloy_transport::TransportErrorKind::custom) @@ -68,8 +62,12 @@ macro_rules! impl_connect { }; } -impl_connect!(std::ffi::OsString => .as_os_str()); +impl_connect!(std::ffi::OsString => |s| s.as_os_str()); +impl_connect!(std::path::PathBuf => |s| s.as_os_str()); +impl_connect!(String => |s| std::ffi::OsStr::new(s)); + #[cfg(unix)] -impl_connect!(std::ffi::CString => .as_c_str()); -impl_connect!(std::path::PathBuf => .as_os_str()); -impl_connect!(String => .as_str()); +impl_connect!(std::ffi::CString => |s| { + use std::os::unix::ffi::OsStrExt; + std::ffi::OsStr::from_bytes(s.to_bytes()) +}); From 77373073d7e86c845af30ae8bb3804d076038e8a Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 18:14:50 +0200 Subject: [PATCH 09/12] a --- crates/transport-ipc/src/connect.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index 5cb2d6c4415..6767646c23b 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -6,10 +6,8 @@ pub(crate) fn to_name(mut path: &std::ffi::OsStr) -> io::Result> { if let Some(name) = path.as_encoded_bytes().strip_prefix(br"\\.\pipe\") { path = unsafe { std::ffi::OsStr::from_encoded_bytes_unchecked(name) } } - ls::ToNsName::to_ns_name::(path) - } else { - ls::ToFsName::to_fs_name::(path) } + ls::ToFsName::to_fs_name::(path) } /// An IPC Connection object. From bee4034863cfa8ec312453dd4428dc7c8788e479 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 18:16:13 +0200 Subject: [PATCH 10/12] b --- crates/transport-ipc/src/connect.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index 6767646c23b..5eb4698cf1b 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -62,7 +62,7 @@ macro_rules! impl_connect { impl_connect!(std::ffi::OsString => |s| s.as_os_str()); impl_connect!(std::path::PathBuf => |s| s.as_os_str()); -impl_connect!(String => |s| std::ffi::OsStr::new(s)); +impl_connect!(String => |s| s.as_ref()); #[cfg(unix)] impl_connect!(std::ffi::CString => |s| { From 9f36a42752883f0fd00000df2b6505e2e8a4f2ff Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 19:02:33 +0200 Subject: [PATCH 11/12] c --- crates/transport-ipc/src/connect.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index 5eb4698cf1b..e6d41ad18bf 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -6,8 +6,10 @@ pub(crate) fn to_name(mut path: &std::ffi::OsStr) -> io::Result> { if let Some(name) = path.as_encoded_bytes().strip_prefix(br"\\.\pipe\") { path = unsafe { std::ffi::OsStr::from_encoded_bytes_unchecked(name) } } + ls::ToNsName::to_ns_name::(path) + } else { + ls::ToFsName::to_fs_name::(path) } - ls::ToFsName::to_fs_name::(path) } /// An IPC Connection object. From 08cd52382e30ca207cd7e1d76638e56b53554f9d Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 5 May 2024 19:08:13 +0200 Subject: [PATCH 12/12] simpler --- crates/transport-ipc/src/connect.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index e6d41ad18bf..d9c10110060 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -1,11 +1,8 @@ use interprocess::local_socket as ls; use std::io; -pub(crate) fn to_name(mut path: &std::ffi::OsStr) -> io::Result> { - if cfg!(windows) { - if let Some(name) = path.as_encoded_bytes().strip_prefix(br"\\.\pipe\") { - path = unsafe { std::ffi::OsStr::from_encoded_bytes_unchecked(name) } - } +pub(crate) fn to_name(path: &std::ffi::OsStr) -> io::Result> { + if cfg!(windows) && !path.as_encoded_bytes().starts_with(br"\\.\pipe\") { ls::ToNsName::to_ns_name::(path) } else { ls::ToFsName::to_fs_name::(path)