update dependency: sysinfo 0.29 -> 0.30

This commit is contained in:
qwjyh 2024-06-19 17:33:58 +09:00
parent 0f7095b229
commit 78b3d0d308
4 changed files with 30 additions and 25 deletions

16
Cargo.lock generated
View file

@ -1048,9 +1048,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.29.11"
version = "0.30.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666"
checksum = "732ffa00f53e6b2af46208fba5718d9662a421049204e156328b66791ffa15ae"
dependencies = [
"cfg-if",
"core-foundation-sys",
@ -1059,7 +1059,7 @@ dependencies = [
"once_cell",
"rayon",
"serde",
"winapi",
"windows",
]
[[package]]
@ -1302,6 +1302,16 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [
"windows-core",
"windows-targets 0.52.5",
]
[[package]]
name = "windows-core"
version = "0.52.0"

View file

@ -14,7 +14,7 @@ keywords = ["cli", "backup"]
[dependencies]
clap = { version = "4.4.0", features = ["cargo", "derive"] }
sysinfo = { version = "0.29.8", features = ["serde"] }
sysinfo = { version = "0.30", features = ["serde"] }
log = "0.4"
clap-verbosity-flag = "2.0.1"
clap_complete = "4.5.1"

View file

@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, BufWriter};
use std::path::Path;
use sysinfo::{System, SystemExt};
use sysinfo::System;
/// YAML file to store known devices.
pub const DEVICESFILE: &str = "devices.yml";
@ -25,18 +25,17 @@ impl Device {
/// Create new `Device` of name `name`. Additional data is obtained via sysinfo.
/// Filling fields which one failed to get is filled with "unknown".
pub fn new(name: String) -> Device {
let sys = System::new();
Device {
name,
os_name: sys.name().unwrap_or_else(|| {
os_name: System::name().unwrap_or_else(|| {
warn!("Failed to get OS name. Saving as \"unknown\".");
"unknown".to_string()
}),
os_version: sys.os_version().unwrap_or_else(|| {
os_version: System::os_version().unwrap_or_else(|| {
warn!("Failed to get OS version. Saving as \"unknown\".");
"unknown".to_string()
}),
hostname: sys.host_name().unwrap_or_else(|| {
hostname: System::host_name().unwrap_or_else(|| {
warn!("Failed to get hostname. Saving as \"unknown\".");
"unknown".to_string()
}),

View file

@ -8,7 +8,7 @@ use byte_unit::Byte;
use serde::{Deserialize, Serialize};
use std::path::{self, Path};
use std::{collections::BTreeMap, fmt};
use sysinfo::{Disk, DiskExt, SystemExt};
use sysinfo::{Disk, Disks};
use super::local_info::{self, LocalInfo};
@ -57,7 +57,10 @@ impl PhysicalDrivePartition {
.to_string();
let fs = disk.file_system();
trace!("fs: {:?}", fs);
let fs = std::str::from_utf8(fs)?;
let fs: String = fs
.to_str()
.context("Failed to convert file_system osstr")?
.to_owned();
let local_info = LocalInfo::new(alias, disk.mount_point().to_path_buf());
Ok(PhysicalDrivePartition {
name,
@ -161,13 +164,9 @@ pub fn select_physical_storage(
) -> Result<PhysicalDrivePartition> {
trace!("select_physical_storage");
// get disk info from sysinfo
let sys_disks =
sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_disks_list());
trace!("refresh");
// sys_disks.refresh_disks_list();
// sys_disks.refresh_disks();
let sys_disks = Disks::new_with_refreshed_list();
trace!("Available disks");
for disk in sys_disks.disks() {
for disk in &sys_disks {
trace!("{:?}", disk)
}
let disk = select_sysinfo_disk(&sys_disks)?;
@ -175,14 +174,13 @@ pub fn select_physical_storage(
Ok(storage)
}
fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
let available_disks = sysinfo
.disks()
fn select_sysinfo_disk(disks: &sysinfo::Disks) -> Result<&Disk> {
let available_disks = disks
.iter()
.enumerate()
.map(|(i, disk)| {
let name = disk.name().to_str().unwrap_or("");
let fs: &str = std::str::from_utf8(disk.file_system()).unwrap_or("unknown");
let fs: &str = disk.file_system().to_str().unwrap_or("unknown");
let kind = format!("{:?}", disk.kind());
let mount_path = disk.mount_point();
let total_space = byte_unit::Byte::from_bytes(disk.total_space().into())
@ -203,10 +201,8 @@ fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
let disk = inquire::Select::new("Select drive:", available_disks).prompt()?;
let disk_num: usize = disk.split(':').next().unwrap().parse().unwrap();
trace!("disk_num: {}", disk_num);
let disk = sysinfo
.disks()
.iter()
.nth(disk_num)
let disk = disks
.get(disk_num)
.context("no disk matched with selected one.")?;
trace!("selected disk: {:?}", disk);
Ok(disk)