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
125 changes: 2 additions & 123 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ opt-level = 3

[patch.crates-io]
# The upstream has outdated dependency on `bindgen` which conflicts with some of our other
# dependencies. Using this fork until the upstream updates.
# dependencies, and xpc-connection has a type mismatch on newer toolchains. Using this fork until
# the upstream updates.
xpc-connection = { git = "https://github.com/madadam/xpc-connection-rs" }
xpc-connection-sys = { git = "https://github.com/madadam/xpc-connection-rs" }

[workspace.lints.clippy]
Expand Down
2 changes: 1 addition & 1 deletion fs_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tokio = { workspace = true, features = ["fs", "io-util", "rt", "sync"] }
tokio-stream = { workspace = true }
walkdir = "2.5.0"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))'.dependencies]
libc = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
33 changes: 33 additions & 0 deletions fs_util/src/safe_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,39 @@ fn blocking_rename_no_replace_atomic(src: &Path, dst: &Path) -> io::Result<()> {
}
}

#[cfg(target_os = "macos")]
fn blocking_rename_no_replace_atomic(src: &Path, dst: &Path) -> io::Result<()> {
use std::ffi::CString;

fn to_cstring(path: &Path) -> io::Result<CString> {
CString::new(path.as_os_str().as_encoded_bytes())
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error.to_string()))
}

// Available since macOS 10.12; fails with EEXIST if dst already exists.
const RENAME_EXCL: u32 = 0x00000004;

unsafe extern "C" {
fn renamex_np(
from: *const libc::c_char,
to: *const libc::c_char,
flags: u32,
) -> libc::c_int;
}

let src = to_cstring(src)?;
let dst = to_cstring(dst)?;

// SAFETY: both pointers are valid null-terminated C strings for the duration of the call.
let result = unsafe { renamex_np(src.as_ptr(), dst.as_ptr(), RENAME_EXCL) };

if result == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
}
}

// Renames `src` to `dst` but fails if `dst` already exists. This is not atomic so it's possible
// that the dst file might still get deleted if it's created concurrently with calling this
// function. This is used only as a fallback on platforms/filesystems which don't support the
Expand Down
2 changes: 1 addition & 1 deletion logtee/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ crate-type = ["rlib", "cdylib"]
file-rotate = "0.8.0"
strip-ansi-escapes = "0.2.1"

[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))'.dependencies]
filedescriptor = "0.8.3"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
4 changes: 1 addition & 3 deletions logtee/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#[cfg(any(target_os = "linux", target_os = "windows"))]
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
#[path = "redirect.rs"]
mod inner;

#[cfg(target_os = "android")]
#[path = "android.rs"]
mod inner;

// TODO: ios and macos

#[cfg(test)]
mod tests;

Expand Down
2 changes: 1 addition & 1 deletion utils/swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ clap = { workspace = true }
ctrlc = { workspace = true }
os_pipe = "1.1.4"

[target.'cfg(any(target_os = "linux", target_os = "osx"))'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
libc = "0.2.126"
Loading