#![cfg(unix)]
use rustix::fs::{fallocate, FallocateFlags};
use std::io;
use tokio::fs::File;
#[must_use]
pub const fn init_fast_alloc() -> bool {
true
}
pub async fn try_fast_preallocate(file: &File, _current_size: u64, size: u64) -> io::Result<bool> {
let std_file = file.try_clone().await?.into_std().await;
let res = tokio::task::spawn_blocking(move || -> io::Result<bool> {
match fallocate(&std_file, FallocateFlags::empty(), 0, size) {
Ok(()) => Ok(true),
Err(_) => Ok(false),
}
})
.await
.unwrap_or(Ok(false))?;
Ok(res)
}