From fef139398c71da5d0981dac4030388400762f715 Mon Sep 17 00:00:00 2001 From: "J. David Lowe" Date: Wed, 27 Nov 2024 10:50:41 -0800 Subject: [PATCH] early return instead of indenting everything --- src/unix/linux/disk.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/unix/linux/disk.rs b/src/unix/linux/disk.rs index 8f1a14f25..be5878200 100644 --- a/src/unix/linux/disk.rs +++ b/src/unix/linux/disk.rs @@ -201,27 +201,27 @@ unsafe fn load_statvfs_values( mount_point: &Path, refresh_kind: DiskRefreshKind, ) -> Option<(u64, u64, bool)> { - if refresh_kind.details() { - let mount_point_cpath = to_cpath(mount_point); - let mut stat: statvfs = mem::zeroed(); - if retry_eintr!(statvfs(mount_point_cpath.as_ptr() as *const _, &mut stat)) == 0 { - let bsize = cast!(stat.f_bsize); - let blocks = cast!(stat.f_blocks); - let bavail = cast!(stat.f_bavail); - let total = bsize.saturating_mul(blocks); - let available = bsize.saturating_mul(bavail); - let is_read_only = (stat.f_flag & libc::ST_RDONLY) != 0; - - if total == 0 { - None - } else { - Some((total, available, is_read_only)) - } - } else { + if !refresh_kind.details() { + return Some((0, 0, false)); + } + + let mount_point_cpath = to_cpath(mount_point); + let mut stat: statvfs = mem::zeroed(); + if retry_eintr!(statvfs(mount_point_cpath.as_ptr() as *const _, &mut stat)) == 0 { + let bsize = cast!(stat.f_bsize); + let blocks = cast!(stat.f_blocks); + let bavail = cast!(stat.f_bavail); + let total = bsize.saturating_mul(blocks); + let available = bsize.saturating_mul(bavail); + let is_read_only = (stat.f_flag & libc::ST_RDONLY) != 0; + + if total == 0 { None + } else { + Some((total, available, is_read_only)) } } else { - Some((0, 0, false)) + None } }