From 08371a722bddaee64069e8e9c72e0bb4909253a4 Mon Sep 17 00:00:00 2001 From: Austin Hartzheim Date: Thu, 9 Apr 2026 11:22:40 -0500 Subject: [PATCH] fix: gate posix_fallocate to Linux OS `posix_fallocate` is not available on Mac. --- src/utils.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index c5c83e2..20111c7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,18 +1,18 @@ use std::fs::File; use std::io; -#[cfg(unix)] +#[cfg(target_os = "linux")] use std::os::fd::AsRawFd; /// Set the length of the file to the specified length. pub(crate) fn set_len(file: &File, len: i64) -> Result<(), io::Error> { - // On Unix platforms, `.set_len()` may not return an error of the disk is full, so we allocate + // On Linux platforms, `.set_len()` may not return an error of the disk is full, so we allocate // the entire file to ensure space is available. - #[cfg(unix)] + #[cfg(target_os = "linux")] match unsafe { libc::posix_fallocate(file.as_raw_fd(), 0, len) } { 0 => Ok(()), err => Err(io::Error::from_raw_os_error(err)), } // Support for non-Linux platforms is best-effort. - #[cfg(not(unix))] - data_file.set_len(STATE_SIZE).map_err(FailedStateRead) + #[cfg(not(target_os = "linux"))] + file.set_len(len).map_err(FailedStateRead) }