Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dlowe committed Nov 27, 2024
1 parent fef1393 commit 78f0362
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
41 changes: 12 additions & 29 deletions src/unix/linux/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 15 additions & 26 deletions src/windows/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -274,11 +271,7 @@ pub(crate) unsafe fn get_list(refreshes: DiskRefreshKind) -> Vec<Disk> {
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();
Expand All @@ -302,11 +295,7 @@ pub(crate) unsafe fn get_list(refreshes: DiskRefreshKind) -> Vec<Disk> {
);
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() {
Expand Down

0 comments on commit 78f0362

Please sign in to comment.