Skip to content

Commit

Permalink
early return instead of indenting everything
Browse files Browse the repository at this point in the history
  • Loading branch information
dlowe committed Nov 27, 2024
1 parent 29381b7 commit fef1393
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/unix/linux/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit fef1393

Please sign in to comment.