Skip to content

Commit 38d5f59

Browse files
fix: gate posix_fallocate to Linux OS
`posix_fallocate` is not available on Mac.
1 parent 7a1f783 commit 38d5f59

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use std::fs::File;
22
use std::io;
3-
#[cfg(unix)]
3+
#[cfg(target_os = "linux")]
44
use std::os::fd::AsRawFd;
55

66
/// Set the length of the file to the specified length.
77
pub(crate) fn set_len(file: &File, len: i64) -> Result<(), io::Error> {
8-
// On Unix platforms, `.set_len()` may not return an error of the disk is full, so we allocate
8+
// On Linux platforms, `.set_len()` may not return an error of the disk is full, so we allocate
99
// the entire file to ensure space is available.
10-
#[cfg(unix)]
10+
#[cfg(target_os = "linux")]
1111
match unsafe { libc::posix_fallocate(file.as_raw_fd(), 0, len) } {
1212
0 => Ok(()),
1313
err => Err(io::Error::from_raw_os_error(err)),
1414
}
1515
// Support for non-Linux platforms is best-effort.
16-
#[cfg(not(unix))]
17-
data_file.set_len(STATE_SIZE).map_err(FailedStateRead)
16+
#[cfg(not(target_os = "linux"))]
17+
file.set_len(leng).map_err(FailedStateRead)
1818
}

0 commit comments

Comments
 (0)