From 08b535d56794bd378a73e491147c934550ac2d45 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 14 Jul 2025 23:35:39 +0200 Subject: [PATCH] radicle: Only set file limits on Unix --- crates/radicle/Cargo.toml | 6 ++++-- crates/radicle/src/io.rs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/radicle/Cargo.toml b/crates/radicle/Cargo.toml index 052c536a..8ec5a9b9 100644 --- a/crates/radicle/Cargo.toml +++ b/crates/radicle/Cargo.toml @@ -26,7 +26,6 @@ fast-glob = { version = "0.3.2" } fastrand = { workspace = true } git2 = { workspace = true, features = ["vendored-libgit2"] } indexmap = { version = "2", features = ["serde"] } -libc = { workspace = true } localtime = { workspace = true, features = ["serde"] } log = { workspace = true, features = ["std"] } multibase = { workspace = true } @@ -46,6 +45,9 @@ tempfile = { workspace = true } thiserror = { workspace = true } unicode-normalization = { version = "0.1" } +[target.'cfg(unix)'.dependencies] +libc = { workspace = true } + [dev-dependencies] emojis = "0.6" jsonschema = { version = "0.30", default-features = false } @@ -53,4 +55,4 @@ pretty_assertions = { workspace = true } qcheck = { workspace = true } qcheck-macros = { workspace = true } radicle-cob = { workspace = true, features = ["stable-commit-ids"] } -radicle-crypto = { workspace = true, features = ["test"] } \ No newline at end of file +radicle-crypto = { workspace = true, features = ["test"] } diff --git a/crates/radicle/src/io.rs b/crates/radicle/src/io.rs index 7e319ef4..a446f834 100644 --- a/crates/radicle/src/io.rs +++ b/crates/radicle/src/io.rs @@ -1,14 +1,25 @@ -use std::fmt; use std::io; +#[cfg(unix)] use libc::{getrlimit, rlim_t, rlimit, setrlimit, RLIMIT_NOFILE}; +#[cfg(unix)] type Int = rlim_t; +#[cfg(not(unix))] +#[inline] +pub fn set_file_limit(_: T) -> io::Result<()> { + Err(io::Error::new( + io::ErrorKind::Unsupported, + "setting file limits is not supported on this platform", + )) +} + /// Sets the open file limit to the given value, or the maximum allowed value. +#[cfg(unix)] pub fn set_file_limit(n: N) -> io::Result where - N: Copy + fmt::Display, + N: Copy + std::fmt::Display, Int: TryFrom, { let Ok(n) = Int::try_from(n) else {