From 63dd1381b7ce0ec8cbf23da1c886e1f2544c3d56 Mon Sep 17 00:00:00 2001 From: wan9chi Date: Thu, 13 Aug 2026 10:35:11 +0800 Subject: [PATCH] refactor(fspy): rename native IPC string types Co-authored-by: GPT-5 Codex --- Cargo.lock | 26 ++++----- Cargo.toml | 2 +- crates/fspy/src/unix/mod.rs | 4 +- .../{native_str => fspy_ipc_str}/Cargo.toml | 2 +- crates/{native_str => fspy_ipc_str}/README.md | 14 ++--- .../{native_str => fspy_ipc_str}/src/lib.rs | 58 +++++++++---------- .../src/windows/detours/nt.rs | 10 ++-- crates/fspy_shared/Cargo.toml | 2 +- crates/fspy_shared/src/ipc/channel/mod.rs | 8 +-- .../src/ipc/{native_path.rs => ipc_path.rs} | 40 ++++++------- crates/fspy_shared/src/ipc/mod.rs | 12 ++-- crates/fspy_shared_unix/src/payload.rs | 8 +-- crates/vt_client/Cargo.toml | 2 +- crates/vt_client/src/lib.rs | 10 ++-- crates/vt_ipc_shared/Cargo.toml | 2 +- crates/vt_ipc_shared/src/lib.rs | 14 ++--- crates/vt_server/Cargo.toml | 2 +- crates/vt_server/src/lib.rs | 8 +-- crates/vt_server/tests/integration.rs | 6 +- 19 files changed, 115 insertions(+), 115 deletions(-) rename crates/{native_str => fspy_ipc_str}/Cargo.toml (93%) rename crates/{native_str => fspy_ipc_str}/README.md (50%) rename crates/{native_str => fspy_ipc_str}/src/lib.rs (74%) rename crates/fspy_shared/src/ipc/{native_path.rs => ipc_path.rs} (59%) diff --git a/Cargo.lock b/Cargo.lock index b18dca386..c78ff18c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1331,6 +1331,15 @@ dependencies = [ "toml", ] +[[package]] +name = "fspy_ipc_str" +version = "0.0.0" +dependencies = [ + "bumpalo", + "bytemuck", + "wincode", +] + [[package]] name = "fspy_nostd" version = "0.0.0" @@ -1412,8 +1421,8 @@ dependencies = [ "bumpalo", "bytemuck", "ctor", + "fspy_ipc_str", "fspy_shm", - "native_str", "rustc-hash", "subprocess_test", "thiserror 2.0.18", @@ -2189,15 +2198,6 @@ dependencies = [ "libloading 0.9.0", ] -[[package]] -name = "native_str" -version = "0.0.0" -dependencies = [ - "bumpalo", - "bytemuck", - "wincode", -] - [[package]] name = "nix" version = "0.28.0" @@ -4298,7 +4298,7 @@ dependencies = [ name = "vt_client" version = "0.0.0" dependencies = [ - "native_str", + "fspy_ipc_str", "rustc-hash", "socket_ipc", "vt_ipc_shared", @@ -4363,7 +4363,7 @@ dependencies = [ name = "vt_ipc_shared" version = "0.0.0" dependencies = [ - "native_str", + "fspy_ipc_str", "rustc-hash", "wincode", ] @@ -4446,8 +4446,8 @@ dependencies = [ name = "vt_server" version = "0.0.0" dependencies = [ + "fspy_ipc_str", "futures", - "native_str", "rustc-hash", "socket_ipc", "thiserror 2.0.18", diff --git a/Cargo.toml b/Cargo.toml index cb823c344..6c96c1867 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,7 +98,7 @@ monostate = "1.0.2" napi = "3" napi-build = "2" napi-derive = "3" -native_str = { path = "crates/native_str" } +fspy_ipc_str = { path = "crates/fspy_ipc_str" } nix = { version = "0.31.2", features = ["dir", "signal"] } ntapi = "0.4.1" nucleo-matcher = "0.3.1" diff --git a/crates/fspy/src/unix/mod.rs b/crates/fspy/src/unix/mod.rs index 7c8008dc3..f1d657436 100644 --- a/crates/fspy/src/unix/mod.rs +++ b/crates/fspy/src/unix/mod.rs @@ -10,7 +10,7 @@ use std::{io, path::Path}; use fspy_seccomp_unotify::supervisor::supervise; use fspy_shared::ipc::PathAccess; #[cfg(not(target_env = "musl"))] -use fspy_shared::ipc::{NativeStr, channel::channel}; +use fspy_shared::ipc::{IpcStr, channel::channel}; #[cfg(target_os = "macos")] use fspy_shared_unix::payload::Artifacts; use fspy_shared_unix::{ @@ -34,7 +34,7 @@ pub struct SpyImpl { artifacts: Artifacts, #[cfg(not(target_env = "musl"))] - preload_path: Box, + preload_path: Box, } impl SpyImpl { diff --git a/crates/native_str/Cargo.toml b/crates/fspy_ipc_str/Cargo.toml similarity index 93% rename from crates/native_str/Cargo.toml rename to crates/fspy_ipc_str/Cargo.toml index 0b84da406..d11091914 100644 --- a/crates/native_str/Cargo.toml +++ b/crates/fspy_ipc_str/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "native_str" +name = "fspy_ipc_str" version = "0.0.0" edition.workspace = true license.workspace = true diff --git a/crates/native_str/README.md b/crates/fspy_ipc_str/README.md similarity index 50% rename from crates/native_str/README.md rename to crates/fspy_ipc_str/README.md index 426f28889..76628cf5f 100644 --- a/crates/native_str/README.md +++ b/crates/fspy_ipc_str/README.md @@ -1,34 +1,34 @@ -# native_str +# fspy_ipc_str A platform-native string type for lossless, zero-copy IPC. -`NativeStr` is a `#[repr(transparent)]` newtype over `[u8]` that represents OS strings in their native encoding: +`IpcStr` is a `#[repr(transparent)]` newtype over `[u8]` that represents OS strings in their native encoding: - **Unix**: raw bytes (same as `OsStr`) - **Windows**: raw wide character bytes (from `&[u16]`, stored as `&[u8]` for uniform handling) ## Why not `OsStr`? -`OsStr` requires valid UTF-8 for serialization. `NativeStr` can be serialized/deserialized losslessly regardless of encoding, with zero-copy support via wincode's `SchemaRead`. +`OsStr` requires valid UTF-8 for serialization. `IpcStr` can be serialized/deserialized losslessly regardless of encoding, with zero-copy support via wincode's `SchemaRead`. ## Limitations -**Not portable across platforms.** The binary representation of a `NativeStr` is platform-specific — Unix uses raw bytes while Windows uses wide character pairs. Deserializing a `NativeStr` that was serialized on a different platform leads to unspecified behavior (garbage data), but is not unsafe. +**Not portable across platforms.** The binary representation of an `IpcStr` is platform-specific — Unix uses raw bytes while Windows uses wide character pairs. Deserializing an `IpcStr` that was serialized on a different platform leads to unspecified behavior (garbage data), but is not unsafe. This type is designed for same-platform IPC (e.g., shared memory between a parent process and its children), not for cross-platform data exchange or persistent storage. For portable paths, use UTF-8 strings instead. ## Usage ```rust -use native_str::NativeStr; +use fspy_ipc_str::IpcStr; // Unix: construct from bytes #[cfg(unix)] -let s: &NativeStr = NativeStr::from_bytes(b"/tmp/foo"); +let s: &IpcStr = IpcStr::from_bytes(b"/tmp/foo"); // Windows: construct from wide chars #[cfg(windows)] -let s: &NativeStr = NativeStr::from_wide(&[0x0048, 0x0069]); // "Hi" +let s: &IpcStr = IpcStr::from_wide(&[0x0048, 0x0069]); // "Hi" // Convert back to OsStr/OsString let os = s.to_cow_os_str(); diff --git a/crates/native_str/src/lib.rs b/crates/fspy_ipc_str/src/lib.rs similarity index 74% rename from crates/native_str/src/lib.rs rename to crates/fspy_ipc_str/src/lib.rs index 647f01035..e7773a640 100644 --- a/crates/native_str/src/lib.rs +++ b/crates/fspy_ipc_str/src/lib.rs @@ -35,18 +35,18 @@ use wincode::{ /// # Limitations /// /// **Not portable across platforms.** The binary representation is platform-specific. -/// Deserializing a `NativeStr` serialized on a different platform leads to unspecified +/// Deserializing an `IpcStr` serialized on a different platform leads to unspecified /// behavior (garbage data), but is not unsafe. Designed for same-platform IPC only. #[derive(TransparentWrapper, PartialEq, Eq, Hash)] #[repr(transparent)] -pub struct NativeStr { +pub struct IpcStr { // On unix, this is the raw bytes of the OsStr. - // On windows, this is safely transmuted from `&[u16]` in `NativeStr::from_wide`. We don't declare it as `&[u16]` to allow zero-copy read. + // On windows, this is safely transmuted from `&[u16]` in `IpcStr::from_wide`. We don't declare it as `&[u16]` to allow zero-copy read. // Transmuting back to `&[u16]` would be unsafe because of different alignments between `u8` and `u16` (See `to_os_string`). data: [u8], } -impl NativeStr { +impl IpcStr { #[cfg(unix)] #[must_use] pub fn from_bytes(bytes: &[u8]) -> &Self { @@ -92,15 +92,15 @@ impl NativeStr { } } -impl Debug for NativeStr { +impl Debug for IpcStr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { ::fmt(self.to_cow_os_str().as_ref(), f) } } -// Manual impl: wincode derive requires Sized, but NativeStr wraps unsized [u8]. +// Manual impl: wincode derive requires Sized, but IpcStr wraps unsized [u8]. // SAFETY: Delegates to `[u8]`'s SchemaWrite impl, preserving its size/write invariants. -unsafe impl SchemaWrite for NativeStr { +unsafe impl SchemaWrite for IpcStr { type Src = Self; fn size_of(src: &Self::Src) -> WriteResult { @@ -112,67 +112,67 @@ unsafe impl SchemaWrite for NativeStr { } } -// SchemaRead for &NativeStr: zero-copy borrow from input bytes +// SchemaRead for &IpcStr: zero-copy borrow from input bytes // SAFETY: Delegates to `&[u8]`'s SchemaRead impl; dst is initialized on Ok. -unsafe impl<'de, C: Config> SchemaRead<'de, C> for &'de NativeStr { - type Dst = &'de NativeStr; +unsafe impl<'de, C: Config> SchemaRead<'de, C> for &'de IpcStr { + type Dst = &'de IpcStr; fn read(mut reader: impl Reader<'de>, dst: &mut MaybeUninit) -> ReadResult<()> { let data: &'de [u8] = <&[u8] as SchemaRead<'de, C>>::get(&mut reader)?; - dst.write(NativeStr::wrap_ref(data)); + dst.write(IpcStr::wrap_ref(data)); Ok(()) } } -// SAFETY: Delegates to `NativeStr`'s SchemaWrite impl, preserving its invariants. -unsafe impl SchemaWrite for Box { +// SAFETY: Delegates to `IpcStr`'s SchemaWrite impl, preserving its invariants. +unsafe impl SchemaWrite for Box { type Src = Self; fn size_of(src: &Self::Src) -> WriteResult { - >::size_of(src) + >::size_of(src) } fn write(writer: impl Writer, src: &Self::Src) -> WriteResult<()> { - >::write(writer, src) + >::write(writer, src) } } -// SchemaRead for Box: owned decode +// SchemaRead for Box: owned decode // SAFETY: Delegates to `&[u8]`'s SchemaRead impl; dst is initialized on Ok. -unsafe impl<'de, C: Config> SchemaRead<'de, C> for Box { +unsafe impl<'de, C: Config> SchemaRead<'de, C> for Box { type Dst = Self; fn read(mut reader: impl Reader<'de>, dst: &mut MaybeUninit) -> ReadResult<()> { let data: &[u8] = <&[u8] as SchemaRead<'de, C>>::get(&mut reader)?; - dst.write(NativeStr::wrap_box(data.into())); + dst.write(IpcStr::wrap_box(data.into())); Ok(()) } } #[cfg(unix)] -impl<'a, S: AsRef + ?Sized> From<&'a S> for &'a NativeStr { +impl<'a, S: AsRef + ?Sized> From<&'a S> for &'a IpcStr { fn from(value: &'a S) -> Self { - NativeStr::from_bytes(value.as_ref().as_bytes()) + IpcStr::from_bytes(value.as_ref().as_bytes()) } } -impl Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { - NativeStr::wrap_box(self.data.into()) + IpcStr::wrap_box(self.data.into()) } } -impl> From for Box { +impl> From for Box { #[cfg(unix)] fn from(value: S) -> Self { - NativeStr::wrap_box(value.as_ref().as_bytes().into()) + IpcStr::wrap_box(value.as_ref().as_bytes().into()) } #[cfg(windows)] fn from(value: S) -> Self { let wide: Vec = value.as_ref().encode_wide().collect(); let data: &[u8] = must_cast_slice(&wide); - NativeStr::wrap_box(data.into()) + IpcStr::wrap_box(data.into()) } } @@ -187,11 +187,11 @@ mod tests { use std::os::windows::ffi::OsStrExt; let wide_str: &[u16] = &[528, 491]; - let native_str = NativeStr::from_wide(wide_str); + let ipc_str = IpcStr::from_wide(wide_str); - let mut encoded = wincode::serialize(native_str).unwrap(); + let mut encoded = wincode::serialize(ipc_str).unwrap(); - let decoded: &NativeStr = wincode::deserialize(&encoded).unwrap(); + let decoded: &IpcStr = wincode::deserialize(&encoded).unwrap(); let decoded_wide = decoded.to_os_string().encode_wide().collect::>(); assert_eq!(decoded_wide, wide_str); @@ -199,7 +199,7 @@ mod tests { encoded.push(0); encoded.copy_within(..encoded_len, 1); - let decoded: &NativeStr = wincode::deserialize(&encoded[1..]).unwrap(); + let decoded: &IpcStr = wincode::deserialize(&encoded[1..]).unwrap(); let decoded_wide = decoded.to_os_string().encode_wide().collect::>(); assert_eq!(decoded_wide, wide_str); } diff --git a/crates/fspy_preload_windows/src/windows/detours/nt.rs b/crates/fspy_preload_windows/src/windows/detours/nt.rs index 12fb8c050..968aea178 100644 --- a/crates/fspy_preload_windows/src/windows/detours/nt.rs +++ b/crates/fspy_preload_windows/src/windows/detours/nt.rs @@ -1,6 +1,6 @@ use std::mem::{offset_of, size_of}; -use fspy_shared::ipc::{AccessMode, NativePath, PathAccess}; +use fspy_shared::ipc::{AccessMode, IpcPath, PathAccess}; use ntapi::{ ntioapi::{ FILE_INFORMATION_CLASS, NtQueryDirectoryFile, NtQueryFullAttributesFile, @@ -96,11 +96,11 @@ static DETOUR_NT_CREATE_USER_PROCESS: Detour< unsafe fn handle_process_image(attribute_list: PPS_ATTRIBUTE_LIST) { // SAFETY: NtCreateUserProcess requires its attribute list to remain valid for this call. if let Some(image_path) = unsafe { read_process_image_attribute(attribute_list) } { - // Sender serialization completes before this call returns, so NativePath does not retain + // Sender serialization completes before this call returns, so IpcPath does not retain // the borrowed PS_ATTRIBUTE_IMAGE_NAME buffer past the NtCreateUserProcess call. // SAFETY: accessing the global client which was initialized during DLL_PROCESS_ATTACH unsafe { global_client() } - .send(PathAccess { mode: AccessMode::READ, path: NativePath::from_wide(image_path) }); + .send(PathAccess { mode: AccessMode::READ, path: IpcPath::from_wide(image_path) }); } } @@ -296,7 +296,7 @@ unsafe fn handle_open(access_mode: impl ToAccessMode, path: impl ToAbsolutePath) // SAFETY: converting access mask to AccessMode via FFI-aware trait PathAccess { mode: access_mode.to_access_mode(), - path: NativePath::from_wide(path), + path: IpcPath::from_wide(path), } }, |wildcard_pos| { @@ -307,7 +307,7 @@ unsafe fn handle_open(access_mode: impl ToAccessMode, path: impl ToAbsolutePath) .unwrap_or(0); PathAccess { mode: AccessMode::READ_DIR, - path: NativePath::from_wide(&path[..slash_pos]), + path: IpcPath::from_wide(&path[..slash_pos]), } }, ); diff --git a/crates/fspy_shared/Cargo.toml b/crates/fspy_shared/Cargo.toml index 67f8ef640..f81449318 100644 --- a/crates/fspy_shared/Cargo.toml +++ b/crates/fspy_shared/Cargo.toml @@ -12,7 +12,7 @@ bumpalo = { workspace = true } bstr = { workspace = true, features = ["alloc", "std"] } bytemuck = { workspace = true, features = ["must_cast", "derive"] } fspy_shm = { workspace = true } -native_str = { workspace = true } +fspy_ipc_str = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } uuid = { workspace = true, features = ["v4"] } diff --git a/crates/fspy_shared/src/ipc/channel/mod.rs b/crates/fspy_shared/src/ipc/channel/mod.rs index fb6dc9c27..2bbaa4fa3 100644 --- a/crates/fspy_shared/src/ipc/channel/mod.rs +++ b/crates/fspy_shared/src/ipc/channel/mod.rs @@ -11,13 +11,13 @@ use tracing::debug; use uuid::Uuid; use wincode::{SchemaRead, SchemaWrite}; -use super::NativeStr; +use super::IpcStr; /// Serializable configuration to create channel senders. #[derive(SchemaWrite, SchemaRead, Clone, Debug)] pub struct ChannelConf { - lock_file_path: Box, - shm_id: Box, + lock_file_path: Box, + shm_id: Box, } /// Creates a mpsc IPC channel with one receiver and a `ChannelConf` that can be passed around processes and used to create multiple senders @@ -61,7 +61,7 @@ impl ChannelConf { pub struct Sender { writer: ShmWriter, - lock_file_path: Box, + lock_file_path: Box, lock_file: File, } diff --git a/crates/fspy_shared/src/ipc/native_path.rs b/crates/fspy_shared/src/ipc/ipc_path.rs similarity index 59% rename from crates/fspy_shared/src/ipc/native_path.rs rename to crates/fspy_shared/src/ipc/ipc_path.rs index eccd8460e..db04f18b7 100644 --- a/crates/fspy_shared/src/ipc/native_path.rs +++ b/crates/fspy_shared/src/ipc/ipc_path.rs @@ -10,7 +10,7 @@ use std::{ use bumpalo::Bump; use bytemuck::TransparentWrapper; -use native_str::NativeStr; +use fspy_ipc_str::IpcStr; use wincode::{ SchemaRead, SchemaWrite, config::Config, @@ -22,44 +22,44 @@ use wincode::{ /// /// On Windows, tracked paths are NT Object Manager paths (`\??` prefix), /// whose raw data is not meaningful for direct consumption. The only way -/// to use the path is through [`strip_path_prefix`](NativePath::strip_path_prefix), +/// to use the path is through [`strip_path_prefix`](IpcPath::strip_path_prefix), /// which normalizes platform differences and extracts a workspace-relative path. #[derive(TransparentWrapper, PartialEq, Eq)] #[repr(transparent)] -pub struct NativePath { - inner: NativeStr, +pub struct IpcPath { + inner: IpcStr, } -// Manual impl: wincode derive requires Sized, but NativePath wraps unsized NativeStr. -// SAFETY: Delegates to `NativeStr`'s SchemaWrite impl, preserving its invariants. -unsafe impl SchemaWrite for NativePath { +// Manual impl: wincode derive requires Sized, but IpcPath wraps unsized IpcStr. +// SAFETY: Delegates to `IpcStr`'s SchemaWrite impl, preserving its invariants. +unsafe impl SchemaWrite for IpcPath { type Src = Self; fn size_of(src: &Self::Src) -> WriteResult { - >::size_of(&src.inner) + >::size_of(&src.inner) } fn write(writer: impl Writer, src: &Self::Src) -> WriteResult<()> { - >::write(writer, &src.inner) + >::write(writer, &src.inner) } } -// SAFETY: Delegates to `&NativeStr`'s SchemaRead impl; dst is initialized on Ok. -unsafe impl<'de, C: Config> SchemaRead<'de, C> for &'de NativePath { - type Dst = &'de NativePath; +// SAFETY: Delegates to `&IpcStr`'s SchemaRead impl; dst is initialized on Ok. +unsafe impl<'de, C: Config> SchemaRead<'de, C> for &'de IpcPath { + type Dst = &'de IpcPath; fn read(mut reader: impl Reader<'de>, dst: &mut MaybeUninit) -> ReadResult<()> { - let inner: &'de NativeStr = <&NativeStr as SchemaRead<'de, C>>::get(&mut reader)?; - dst.write(NativePath::wrap_ref(inner)); + let inner: &'de IpcStr = <&IpcStr as SchemaRead<'de, C>>::get(&mut reader)?; + dst.write(IpcPath::wrap_ref(inner)); Ok(()) } } -impl NativePath { +impl IpcPath { #[cfg(windows)] #[must_use] pub fn from_wide(wide: &[u16]) -> &Self { - Self::wrap_ref(NativeStr::from_wide(wide)) + Self::wrap_ref(IpcStr::from_wide(wide)) } pub fn clone_in<'bump>(&self, bump: &'bump Bump) -> &'bump Self { @@ -76,15 +76,15 @@ impl NativePath { } } -impl Debug for NativePath { +impl Debug for IpcPath { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - ::fmt(&self.inner, f) + ::fmt(&self.inner, f) } } #[cfg(unix)] -impl<'a, S: AsRef + ?Sized> From<&'a S> for &'a NativePath { +impl<'a, S: AsRef + ?Sized> From<&'a S> for &'a IpcPath { fn from(value: &'a S) -> Self { - NativePath::wrap_ref(NativeStr::from_bytes(value.as_ref().as_bytes())) + IpcPath::wrap_ref(IpcStr::from_bytes(value.as_ref().as_bytes())) } } diff --git a/crates/fspy_shared/src/ipc/mod.rs b/crates/fspy_shared/src/ipc/mod.rs index c7236e5d6..9c49e7371 100644 --- a/crates/fspy_shared/src/ipc/mod.rs +++ b/crates/fspy_shared/src/ipc/mod.rs @@ -1,11 +1,11 @@ #[cfg(not(target_env = "musl"))] pub mod channel; -mod native_path; +mod ipc_path; use std::fmt::Debug; use bitflags::bitflags; -pub use native_path::NativePath; -pub use native_str::NativeStr; +pub use fspy_ipc_str::IpcStr; +pub use ipc_path::IpcPath; use wincode::{SchemaRead, SchemaWrite}; #[derive(SchemaWrite, SchemaRead, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] @@ -34,16 +34,16 @@ impl Debug for AccessMode { #[derive(SchemaWrite, SchemaRead, Debug, Clone, Copy, PartialEq, Eq)] pub struct PathAccess<'a> { pub mode: AccessMode, - pub path: &'a NativePath, + pub path: &'a IpcPath, // TODO: add follow_symlinks (O_NOFOLLOW) } impl<'a> PathAccess<'a> { - pub fn read(path: impl Into<&'a NativePath>) -> Self { + pub fn read(path: impl Into<&'a IpcPath>) -> Self { Self { mode: AccessMode::READ, path: path.into() } } - pub fn read_dir(path: impl Into<&'a NativePath>) -> Self { + pub fn read_dir(path: impl Into<&'a IpcPath>) -> Self { Self { mode: AccessMode::READ_DIR, path: path.into() } } } diff --git a/crates/fspy_shared_unix/src/payload.rs b/crates/fspy_shared_unix/src/payload.rs index cd196c960..14f30229a 100644 --- a/crates/fspy_shared_unix/src/payload.rs +++ b/crates/fspy_shared_unix/src/payload.rs @@ -1,7 +1,7 @@ use base64::{Engine as _, prelude::BASE64_STANDARD_NO_PAD}; use bstr::BString; #[cfg(not(target_env = "musl"))] -use fspy_shared::ipc::NativeStr; +use fspy_shared::ipc::IpcStr; #[cfg(not(target_env = "musl"))] use fspy_shared::ipc::channel::ChannelConf; use wincode::{SchemaRead, SchemaWrite}; @@ -12,7 +12,7 @@ pub struct Payload { pub ipc_channel_conf: ChannelConf, #[cfg(not(target_env = "musl"))] - pub preload_path: Box, + pub preload_path: Box, #[cfg(target_os = "macos")] pub artifacts: Artifacts, @@ -28,8 +28,8 @@ pub struct Payload { #[cfg(target_os = "macos")] #[derive(Debug, SchemaWrite, SchemaRead, Clone)] pub struct Artifacts { - pub bash_path: Box, - pub coreutils_path: Box, + pub bash_path: Box, + pub coreutils_path: Box, } pub(crate) const PAYLOAD_ENV_NAME: &str = "FSPY_PAYLOAD"; diff --git a/crates/vt_client/Cargo.toml b/crates/vt_client/Cargo.toml index 5565baca4..3a5bfeeac 100644 --- a/crates/vt_client/Cargo.toml +++ b/crates/vt_client/Cargo.toml @@ -7,7 +7,7 @@ publish = false rust-version.workspace = true [dependencies] -native_str = { workspace = true } +fspy_ipc_str = { workspace = true } rustc-hash = { workspace = true } socket_ipc = { workspace = true } vt_path = { workspace = true } diff --git a/crates/vt_client/src/lib.rs b/crates/vt_client/src/lib.rs index 2f212b248..242d86294 100644 --- a/crates/vt_client/src/lib.rs +++ b/crates/vt_client/src/lib.rs @@ -5,7 +5,7 @@ use std::{ sync::Arc, }; -use native_str::NativeStr; +use fspy_ipc_str::IpcStr; use rustc_hash::FxHashMap; use socket_ipc::Client as Stream; use vt_ipc_shared::{ @@ -107,7 +107,7 @@ impl Client { /// /// Returns an error if the request or response fails. pub fn get_env(&self, name: &OsStr, tracked: bool) -> io::Result>> { - let name = Box::::from(name); + let name = Box::::from(name); self.send(&Request::GetEnv { name: &name, tracked })?; let response: GetEnvResponse = self.recv()?; @@ -175,12 +175,12 @@ impl Client { } } -fn resolve_path(path: &OsStr) -> io::Result> { +fn resolve_path(path: &OsStr) -> io::Result> { if let Some(abs) = AbsolutePath::new(path) { - return Ok(Box::::from(abs.as_path().as_os_str())); + return Ok(Box::::from(abs.as_path().as_os_str())); } let mut absolute = vt_path::current_dir()?; absolute.push(path); - Ok(Box::::from(absolute.as_absolute_path().as_path().as_os_str())) + Ok(Box::::from(absolute.as_absolute_path().as_path().as_os_str())) } diff --git a/crates/vt_ipc_shared/Cargo.toml b/crates/vt_ipc_shared/Cargo.toml index 006b8d195..1647f0baf 100644 --- a/crates/vt_ipc_shared/Cargo.toml +++ b/crates/vt_ipc_shared/Cargo.toml @@ -7,7 +7,7 @@ publish = false rust-version.workspace = true [dependencies] -native_str = { workspace = true } +fspy_ipc_str = { workspace = true } rustc-hash = { workspace = true } wincode = { workspace = true, features = ["derive"] } diff --git a/crates/vt_ipc_shared/src/lib.rs b/crates/vt_ipc_shared/src/lib.rs index 8c3f7fb15..fb041c629 100644 --- a/crates/vt_ipc_shared/src/lib.rs +++ b/crates/vt_ipc_shared/src/lib.rs @@ -1,4 +1,4 @@ -use native_str::NativeStr; +use fspy_ipc_str::IpcStr; use rustc_hash::FxHashMap; use wincode::{SchemaRead, SchemaWrite}; @@ -28,9 +28,9 @@ pub const NODE_CLIENT_PATH_ENV_NAME: &str = "VP_RUN_NODE_CLIENT_PATH"; /// will still consume every buffered frame. #[derive(Debug, SchemaWrite, SchemaRead)] pub enum Request<'a> { - IgnoreInput(&'a NativeStr), - IgnoreOutput(&'a NativeStr), - GetEnv { name: &'a NativeStr, tracked: bool }, + IgnoreInput(&'a IpcStr), + IgnoreOutput(&'a IpcStr), + GetEnv { name: &'a IpcStr, tracked: bool }, GetEnvs { query: EnvQuery<'a>, tracked: bool }, DisableCache, } @@ -43,12 +43,12 @@ pub enum EnvQuery<'a> { #[derive(Debug, SchemaWrite, SchemaRead)] pub struct GetEnvResponse { - pub env_value: Option>, + pub env_value: Option>, } #[derive(Debug, SchemaWrite, SchemaRead)] pub struct GetEnvsResponse { /// Match snapshot for the glob pattern. Keys/values are byte-faithful - /// (`NativeStr`) so non-UTF-8 env values are preserved over the wire. - pub entries: FxHashMap, Box>, + /// (`IpcStr`) so non-UTF-8 env values are preserved over the wire. + pub entries: FxHashMap, Box>, } diff --git a/crates/vt_server/Cargo.toml b/crates/vt_server/Cargo.toml index 4cf2f69c4..cb06cfc60 100644 --- a/crates/vt_server/Cargo.toml +++ b/crates/vt_server/Cargo.toml @@ -8,7 +8,7 @@ rust-version.workspace = true [dependencies] futures = { workspace = true } -native_str = { workspace = true } +fspy_ipc_str = { workspace = true } rustc-hash = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["io-util", "rt", "macros"] } diff --git a/crates/vt_server/src/lib.rs b/crates/vt_server/src/lib.rs index 3fbdde56a..8e4ca4f05 100644 --- a/crates/vt_server/src/lib.rs +++ b/crates/vt_server/src/lib.rs @@ -5,8 +5,8 @@ use std::{ sync::Arc, }; +use fspy_ipc_str::IpcStr; use futures::{FutureExt, StreamExt, future::LocalBoxFuture, stream::FuturesUnordered}; -use native_str::NativeStr; use rustc_hash::{FxHashMap, FxHashSet}; use socket_ipc::{Server as TransportServer, ServerConnection as Stream}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; @@ -361,11 +361,11 @@ async fn handle_client(mut stream: Stream, handler: &RefCell) -> // the rationale. match request { Request::IgnoreInput(ns) => { - let path = native_str_to_abs_path(ns)?; + let path = ipc_str_to_abs_path(ns)?; handler.borrow_mut().ignore_input(&path); } Request::IgnoreOutput(ns) => { - let path = native_str_to_abs_path(ns)?; + let path = ipc_str_to_abs_path(ns)?; handler.borrow_mut().ignore_output(&path); } Request::DisableCache => { @@ -417,7 +417,7 @@ fn is_client_gone(err: &io::Error) -> bool { matches!(err.kind(), io::ErrorKind::UnexpectedEof | io::ErrorKind::BrokenPipe) } -fn native_str_to_abs_path(ns: &NativeStr) -> Result, Error> { +fn ipc_str_to_abs_path(ns: &IpcStr) -> Result, Error> { let os_str = ns.to_cow_os_str(); AbsolutePath::new(&*os_str) .map(Arc::from) diff --git a/crates/vt_server/tests/integration.rs b/crates/vt_server/tests/integration.rs index a30e28220..8f15d48ea 100644 --- a/crates/vt_server/tests/integration.rs +++ b/crates/vt_server/tests/integration.rs @@ -5,7 +5,7 @@ use std::{ thread, }; -use native_str::NativeStr; +use fspy_ipc_str::IpcStr; use rustc_hash::FxHashMap; use socket_ipc::Client as RawStream; use tokio::runtime::Builder; @@ -113,7 +113,7 @@ fn raw_disable_cache_request_disables_cache() { let name = &envs[0].1; let mut stream = connect_raw(name); send_frame(&mut stream, &Request::DisableCache); - let flush_name: Box = OsStr::new("__VP_TEST_FLUSH__").into(); + let flush_name: Box = OsStr::new("__VP_TEST_FLUSH__").into(); send_frame(&mut stream, &Request::GetEnv { name: &flush_name, tracked: false }); let _ = recv_get_env_response(&mut stream); }) @@ -244,7 +244,7 @@ fn server_returns_error_on_non_absolute_path() { let name = &envs[0].1; let mut stream = connect_raw(name); - let ns: Box = OsStr::new("relative/path").into(); + let ns: Box = OsStr::new("relative/path").into(); send_frame(&mut stream, &Request::IgnoreInput(&ns)); let mut buf = [0u8; 1];