Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Only set file limits on Unix
Lorenz Leutgeb committed 11 months ago
commit 43bf1c52b9004ba388c219e9f1c29ff31fcabefd
parent fcbe0635763f5bc7d1a833ecd0183630803f3016
2 files changed +16 -3
modified crates/radicle/Cargo.toml
@@ -24,7 +24,6 @@ crossbeam-channel = { workspace = true }
cyphernet = { workspace = true, features = ["tor", "dns", "p2p-ed25519"] }
fastrand = { workspace = true }
git2 = { workspace = true, features = ["vendored-libgit2"] }
-
libc = { workspace = true }
localtime = { workspace = true, features = ["serde"] }
log = { workspace = true, features = ["std"] }
multibase = { workspace = true }
@@ -44,6 +43,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 }
modified 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>(_: 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 {