radicle: Only set file limits on Unix

This commit is contained in:
Lorenz Leutgeb 2025-07-14 23:35:39 +02:00
parent e7fb5647ac
commit 08b535d567
2 changed files with 17 additions and 4 deletions

View File

@ -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"] }
radicle-crypto = { workspace = true, features = ["test"] }

View File

@ -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>(_: 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: N) -> io::Result<Int>
where
N: Copy + fmt::Display,
N: Copy + std::fmt::Display,
Int: TryFrom<N>,
{
let Ok(n) = Int::try_from(n) else {