Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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)
}
Loading