Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
samin-cf committed Nov 3, 2024
1 parent a4e7bd8 commit 10a239d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/common/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ impl Disk {

/// Returns number of bytes read and written by the disk
///
/// ⚠️ Note that FreeBSD is not yet supported
///
/// ```no_run
/// use sysinfo::Disks;
///
Expand Down
1 change: 1 addition & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) mod user;
/// println!("[{:?}] disk usage: {:?}", disk.name(), disk.usage());
/// }
/// ```
#[cfg(any(feature = "disk", feature = "system"))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd)]
pub struct DiskUsage {
/// Total number of written bytes.
Expand Down
6 changes: 1 addition & 5 deletions src/unix/apple/macos/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ pub(crate) fn get_disk_type(bsd_name: &[u8]) -> Option<DiskKind> {
}) {
Some(disk_type)
} else {
// Many external drive vendors do not advertise their device's storage medium.
//
// In these cases, assuming that there were _any_ properties about them registered, we fallback
// to `HDD` when no storage medium is provided by the device instead of `Unknown`.
Some(DiskKind::HDD)
Some(DiskKind::Unknown(-1))
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/unknown/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub(crate) struct DiskInner;

impl DiskInner {
pub(crate) fn kind(&self) -> DiskKind {
unreachable!()
DiskKind::Unknown(-1)
}

pub(crate) fn name(&self) -> &OsStr {
unreachable!()
OsStr::new("")
}

pub(crate) fn file_system(&self) -> &OsStr {
Expand Down Expand Up @@ -44,7 +44,7 @@ impl DiskInner {
}

pub(crate) fn usage(&self) -> DiskUsage {
unreachable!()
DiskUsage::default()
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/windows/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,10 @@ fn get_disk_io(device_path: &[u16], handle: Option<HandleWrapper>) -> Option<(u6
sysinfo_debug!("Error: DeviceIoControl(IOCTL_DISK_PERFORMANCE) = {:?}", err);
err
})
.ok()
.and_then(|_| {
disk_perf
.BytesRead
.try_into()
.ok()
.zip(disk_perf.BytesWritten.try_into().ok())
})
.ok()?;

Some((
disk_perf.BytesRead.try_into().ok()?,
disk_perf.BytesWritten.try_into().ok()?,
))
}

0 comments on commit 10a239d

Please sign in to comment.