Skip to content

Commit 59e1c91

Browse files
committed
fix(compact): cross-platform statvfs type compatibility
Cast f_bavail and f_frsize to u64 for macOS compatibility. On macOS these are u32, while on Linux they are u64.
1 parent 640af81 commit 59e1c91

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • src/cortex-compact/src/auto_compaction

src/cortex-compact/src/auto_compaction/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn chrono_timestamp() -> String {
2020

2121
/// Estimate available disk space in bytes (platform-specific).
2222
#[cfg(unix)]
23+
#[allow(clippy::unnecessary_cast)] // Cast needed for cross-platform: macOS has u32, Linux has u64
2324
pub fn available_disk_space(path: &Path) -> io::Result<u64> {
2425
use std::ffi::CString;
2526
use std::mem::MaybeUninit;
@@ -31,7 +32,8 @@ pub fn available_disk_space(path: &Path) -> io::Result<u64> {
3132
let mut statvfs = MaybeUninit::<libc::statvfs>::uninit();
3233
if libc::statvfs(c_path.as_ptr(), statvfs.as_mut_ptr()) == 0 {
3334
let statvfs = statvfs.assume_init();
34-
Ok(statvfs.f_bavail * statvfs.f_frsize)
35+
// Cast to u64 for cross-platform compatibility (macOS has u32 for f_bavail)
36+
Ok((statvfs.f_bavail as u64) * (statvfs.f_frsize as u64))
3537
} else {
3638
Err(io::Error::last_os_error())
3739
}

0 commit comments

Comments
 (0)