Skip to content

Commit 410364c

Browse files
committed
refactor: replace NativeString with Box<NativeStr>
1 parent 96bd2eb commit 410364c

File tree

11 files changed

+158
-165
lines changed

11 files changed

+158
-165
lines changed

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fspy/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ ctor = { workspace = true }
4949
test-log = { workspace = true }
5050
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "fs", "io-std"] }
5151

52-
[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dev-dependencies]
53-
fspy_test_bin = { path = "../fspy_test_bin", artifact = "bin", target = "aarch64-unknown-linux-musl" }
52+
# [target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dev-dependencies]
53+
# fspy_test_bin = { path = "../fspy_test_bin", artifact = "bin", target = "aarch64-unknown-linux-musl" }
5454

55-
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dev-dependencies]
56-
fspy_test_bin = { path = "../fspy_test_bin", artifact = "bin", target = "x86_64-unknown-linux-musl" }
55+
# [target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dev-dependencies]
56+
# fspy_test_bin = { path = "../fspy_test_bin", artifact = "bin", target = "x86_64-unknown-linux-musl" }
5757

5858
[build-dependencies]
5959
anyhow = { workspace = true }

crates/fspy/src/unix/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{io, path::Path};
88

99
#[cfg(target_os = "linux")]
1010
use fspy_seccomp_unotify::supervisor::supervise;
11-
use fspy_shared::ipc::{NativeString, PathAccess, channel::channel};
11+
use fspy_shared::ipc::{NativeStr, PathAccess, channel::channel};
1212
#[cfg(target_os = "macos")]
1313
use fspy_shared_unix::payload::Artifacts;
1414
use fspy_shared_unix::{
@@ -28,12 +28,12 @@ use crate::{
2828
ipc::{OwnedReceiverLockGuard, SHM_CAPACITY},
2929
};
3030

31-
#[derive(Debug, Clone)]
31+
#[derive(Debug)]
3232
pub struct SpyImpl {
3333
#[cfg(target_os = "macos")]
3434
artifacts: Artifacts,
3535

36-
preload_path: NativeString,
36+
preload_path: Box<NativeStr>,
3737
}
3838

3939
const PRELOAD_CDYLIB_BINARY: &[u8] = include_bytes!(env!("CARGO_CDYLIB_FILE_FSPY_PRELOAD_UNIX"));

crates/fspy_preload_unix/src/client/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
pub mod convert;
22
pub mod raw_exec;
33

4-
use std::{fmt::Debug, num::NonZeroUsize, sync::OnceLock};
4+
use std::{
5+
ffi::OsStr, fmt::Debug, num::NonZeroUsize, os::unix::ffi::OsStrExt as _, sync::OnceLock,
6+
};
57

68
use bincode::{enc::write::SizeWriter, encode_into_slice, encode_into_writer};
79
use convert::{ToAbsolutePath, ToAccessMode};
@@ -55,7 +57,7 @@ impl Client {
5557
// ipc channel not available, skip sending
5658
return Ok(());
5759
};
58-
let path = path_access.path.as_bstr();
60+
let path = path_access.path.as_os_str().as_bytes();
5961
if path.starts_with(b"/dev/")
6062
|| (cfg!(target_os = "linux")
6163
&& (path.starts_with(b"/proc/") || path.starts_with(b"/sys/")))
@@ -101,7 +103,7 @@ impl Client {
101103
let Some(abs_path) = abs_path else {
102104
return Ok(Ok(()));
103105
};
104-
Ok(self.send(PathAccess { mode, path: abs_path.into() }))
106+
Ok(self.send(PathAccess { mode, path: OsStr::from_bytes(abs_path).into() }))
105107
})
106108
}??;
107109

crates/fspy_shared/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ allocator-api2 = { workspace = true }
99
bincode = { workspace = true }
1010
bitflags = { workspace = true }
1111
bstr = { workspace = true }
12-
bytemuck = { workspace = true, features = ["must_cast"] }
12+
bytemuck = { workspace = true, features = ["must_cast", "derive"] }
1313
shared_memory = { workspace = true, features = ["logging"] }
1414
thiserror = { workspace = true }
1515
tracing = { workspace = true }

crates/fspy_shared/src/ipc/channel/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use shm_io::{ShmReader, ShmWriter};
1111
use tracing::debug;
1212
use uuid::Uuid;
1313

14-
use super::NativeString;
14+
use super::NativeStr;
1515

1616
/// Serializable configuration to create channel senders.
1717
#[derive(Encode, Decode, Clone, Debug)]
1818
pub struct ChannelConf {
19-
lock_file_path: NativeString,
19+
lock_file_path: Box<NativeStr>,
2020
shm_id: Arc<str>,
2121
shm_size: usize,
2222
}
@@ -69,7 +69,7 @@ impl ChannelConf {
6969

7070
pub struct Sender {
7171
writer: ShmWriter<Shmem>,
72-
lock_file_path: NativeString,
72+
lock_file_path: Box<NativeStr>,
7373
lock_file: File,
7474
}
7575

crates/fspy_shared/src/ipc/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt::Debug;
55

66
use bincode::{BorrowDecode, Encode, config::Configuration};
77
use bitflags::bitflags;
8-
pub use native_str::{NativeStr, NativeString};
8+
pub use native_str::NativeStr;
99

1010
pub const BINCODE_CONFIG: Configuration = bincode::config::standard();
1111

@@ -35,16 +35,16 @@ impl Debug for AccessMode {
3535
#[derive(Encode, BorrowDecode, Debug, Clone, Copy)]
3636
pub struct PathAccess<'a> {
3737
pub mode: AccessMode,
38-
pub path: NativeStr<'a>,
38+
pub path: &'a NativeStr,
3939
// TODO: add follow_symlinks (O_NOFOLLOW)
4040
}
4141

4242
impl<'a> PathAccess<'a> {
43-
pub fn read(path: impl Into<NativeStr<'a>>) -> Self {
43+
pub fn read(path: impl Into<&'a NativeStr>) -> Self {
4444
Self { mode: AccessMode::READ, path: path.into() }
4545
}
4646

47-
pub fn read_dir(path: impl Into<NativeStr<'a>>) -> Self {
47+
pub fn read_dir(path: impl Into<&'a NativeStr>) -> Self {
4848
Self { mode: AccessMode::READ_DIR, path: path.into() }
4949
}
5050
}

0 commit comments

Comments
 (0)