diff --git a/src/unix/linux/disk.rs b/src/unix/linux/disk.rs index be5878200..9e2013069 100644 --- a/src/unix/linux/disk.rs +++ b/src/unix/linux/disk.rs @@ -122,15 +122,13 @@ impl DiskInner { } if refresh_kind.details() { - let (total_space, available_space, is_read_only) = - match unsafe { load_statvfs_values(&self.mount_point, refresh_kind) } { - Some((total, available, is_read_only)) => (total, available, is_read_only), - None => (0, 0, false), - }; - - self.total_space = total_space; - self.available_space = available_space; - self.is_read_only = is_read_only; + if let Some((total_space, available_space, is_read_only)) = + unsafe { load_statvfs_values(&self.mount_point) } + { + self.total_space = total_space; + self.available_space = available_space; + self.is_read_only = is_read_only; + } } true @@ -197,14 +195,7 @@ fn get_actual_device_name(device: &OsStr) -> String { .unwrap_or_default() } -unsafe fn load_statvfs_values( - mount_point: &Path, - refresh_kind: DiskRefreshKind, -) -> Option<(u64, u64, bool)> { - if !refresh_kind.details() { - return Some((0, 0, false)); - } - +unsafe fn load_statvfs_values(mount_point: &Path) -> Option<(u64, u64, bool)> { 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 { @@ -240,23 +231,15 @@ fn new_disk( }; let (total_space, available_space, is_read_only) = if refresh_kind.details() { - match unsafe { load_statvfs_values(mount_point, refresh_kind) } { - Some((total_space, available_space, is_read_only)) => { - (total_space, available_space, is_read_only) - } - None => (0, 0, false), - } + unsafe { load_statvfs_values(mount_point).unwrap_or((0, 0, false)) } } else { (0, 0, false) }; - let is_removable = if refresh_kind.details() { - removable_entries + let is_removable = refresh_kind.details() + && removable_entries .iter() - .any(|e| e.as_os_str() == device_name) - } else { - false - }; + .any(|e| e.as_os_str() == device_name); let (actual_device_name, read_bytes, written_bytes) = if refresh_kind.io_usage() { let actual_device_name = get_actual_device_name(device_name); diff --git a/src/windows/disk.rs b/src/windows/disk.rs index 9588cac15..f9efc6dfb 100644 --- a/src/windows/disk.rs +++ b/src/windows/disk.rs @@ -173,26 +173,23 @@ impl DiskInner { } if refreshes.io_usage() { - let Some((read_bytes, written_bytes)) = get_disk_io(&self.device_path, None) else { + if let Some((read_bytes, written_bytes)) = get_disk_io(&self.device_path, None) { + self.old_read_bytes = self.read_bytes; + self.old_written_bytes = self.written_bytes; + self.read_bytes = read_bytes; + self.written_bytes = written_bytes; + } else { sysinfo_debug!("Failed to update disk i/o stats"); - return false; - }; - - self.old_read_bytes = self.read_bytes; - self.old_written_bytes = self.written_bytes; - self.read_bytes = read_bytes; - self.written_bytes = written_bytes; + } } if refreshes.details() { - let (total_space, available_space) = if refreshes.details() { - unsafe { get_drive_size(&self.mount_point).unwrap_or_default() } - } else { - (0, 0) - }; - - self.total_space = total_space; - self.available_space = available_space; + if let Some((total_space, available_space)) = + unsafe { get_drive_size(&self.mount_point) } + { + self.total_space = total_space; + self.available_space = available_space; + } } false } @@ -274,11 +271,7 @@ pub(crate) unsafe fn get_list(refreshes: DiskRefreshKind) -> Vec { let raw_volume_name = PCWSTR::from_raw(volume_name.as_ptr()); let drive_type = GetDriveTypeW(raw_volume_name); - let is_removable = if refreshes.details() { - drive_type == DRIVE_REMOVABLE - } else { - false - }; + let is_removable = refreshes.details() && drive_type == DRIVE_REMOVABLE; if drive_type != DRIVE_FIXED && drive_type != DRIVE_REMOVABLE { return Vec::new(); @@ -302,11 +295,7 @@ pub(crate) unsafe fn get_list(refreshes: DiskRefreshKind) -> Vec { ); return Vec::new(); } - let is_read_only = if refreshes.details() { - (flags & FILE_READ_ONLY_VOLUME) != 0 - } else { - false - }; + let is_read_only = refreshes.details() && (flags & FILE_READ_ONLY_VOLUME) != 0; let mount_paths = get_volume_path_names_for_volume_name(&volume_name[..]); if mount_paths.is_empty() {