Skip to content

Commit

Permalink
more restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Mar 17, 2023
1 parent 5b32997 commit 0cf3106
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 97 deletions.
12 changes: 5 additions & 7 deletions src/app/data_harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,21 @@ impl DataCollector {
if self.widgets_to_harvest.use_disk {
#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))]
{
self.data.disks = disks::usage::get_disk_usage(
&self.filters.disk_filter,
&self.filters.mount_filter,
)
.ok();
self.data.disks =
disks::get_disk_usage(&self.filters.disk_filter, &self.filters.mount_filter)
.ok();
}

#[cfg(target_os = "windows")]
{
self.data.disks = Some(disks::usage::get_disk_usage(
self.data.disks = Some(disks::get_disk_usage(
&self.sys,
&self.filters.disk_filter,
&self.filters.mount_filter,
));
}

self.data.io = disks::io::get_io_usage().ok();
self.data.io = disks::get_io_usage().ok();
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/app/data_harvester/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
use std::collections::HashMap;

pub mod io;
pub mod usage;
cfg_if::cfg_if! {
if #[cfg(target_os = "freebsd")] {
pub mod freebsd;
pub use self::freebsd::*;
} else if #[cfg(target_os = "windows")] {
pub mod windows;
pub use self::windows::*;
} else if #[cfg(target_os = "linux")] {
pub mod unix;
pub use self::unix::*;
} else if #[cfg(target_os = "macos")] {
pub mod unix;
pub use self::unix::*;
}
}

#[derive(Debug, Clone, Default)]
pub struct DiskHarvest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ use std::io;

use serde::Deserialize;

use crate::app::Filter;
use crate::data_harvester::deserialize_xo;
use crate::data_harvester::disks::DiskHarvest;
use crate::utils::error;
use crate::{
app::Filter,
data_harvester::{
deserialize_xo,
disks::{DiskHarvest, IoHarvest},
},
utils::error,
};

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -25,6 +29,18 @@ struct FileSystem {
mounted_on: String,
}

pub fn get_io_usage() -> error::Result<IoHarvest> {
let io_harvest = get_disk_info().map(|storage_system_information| {
storage_system_information
.filesystem
.into_iter()
.map(|disk| (disk.name, None))
.collect()
})?;

Ok(io_harvest)
}

pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
) -> error::Result<Vec<DiskHarvest>> {
Expand Down
15 changes: 0 additions & 15 deletions src/app/data_harvester/disks/io.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/data_harvester/disks/io/freebsd.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/app/data_harvester/disks/io/linux.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/app/data_harvester/disks/io/macos.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/app/data_harvester/disks/io/windows.rs

This file was deleted.

31 changes: 31 additions & 0 deletions src/app/data_harvester/disks/unix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![allow(unused_imports)] // FIXME: Remove this

use crate::{
app::{
data_harvester::disks::{DiskHarvest, IoHarvest},
filter::Filter,
},
utils::error,
};

cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
mod linux;
use linux::*;
} else if #[cfg(not(target_os = "linux"))] {
mod other;
use other::*;
}
}

pub fn get_io_usage() -> error::Result<IoHarvest> {
Ok(IoHarvest::default())
}

#[allow(dead_code)]
#[allow(unused_variables)]
pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
) -> error::Result<Vec<DiskHarvest>> {
Ok(vec![])
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
use heim::disk::Partition;

use crate::{
app::{data_harvester::disks::DiskHarvest, filter::Filter},
utils::error,
};

#[allow(dead_code)]
#[allow(unused_variables)]
pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
) -> error::Result<Vec<DiskHarvest>> {
Ok(vec![])
}

#[allow(dead_code)]
#[cfg(target_os = "linux")]
fn get_device_name(partition: &Partition) -> String {
if let Some(device) = partition.device() {
// See if this disk is actually mounted elsewhere on Linux...
Expand Down Expand Up @@ -45,16 +31,3 @@ fn get_device_name(partition: &Partition) -> String {
"Name Unavailable".to_string()
}
}

#[allow(dead_code)]
#[cfg(not(target_os = "linux"))]
fn get_device_name(partition: &Partition) -> String {
if let Some(device) = partition.device() {
device
.to_os_string()
.into_string()
.unwrap_or_else(|_| "Name Unavailable".to_string())
} else {
"Name Unavailable".to_string()
}
}
13 changes: 13 additions & 0 deletions src/app/data_harvester/disks/unix/other.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use heim::disk::Partition;

#[allow(dead_code)]
fn get_device_name(partition: &Partition) -> String {
if let Some(device) = partition.device() {
device
.to_os_string()
.into_string()
.unwrap_or_else(|_| "Name Unavailable".to_string())
} else {
"Name Unavailable".to_string()
}
}
12 changes: 0 additions & 12 deletions src/app/data_harvester/disks/usage.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
use sysinfo::{DiskExt, System, SystemExt};

use crate::app::filter::Filter;
use crate::data_harvester::disks::DiskHarvest;
use crate::{
app::{
data_harvester::disks::{DiskHarvest, IoHarvest},
filter::Filter,
},
utils::error,
};

pub fn get_io_usage() -> error::Result<IoHarvest> {
Ok(IoHarvest::default())
}

pub(crate) fn get_disk_usage(
sys: &System, disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
Expand Down

0 comments on commit 0cf3106

Please sign in to comment.