diff --git a/Cargo.lock b/Cargo.lock index 43e9fa8..6766926 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,9 +115,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -909,9 +909,9 @@ checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" [[package]] name = "proc-macro2" -version = "1.0.84" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1246,9 +1246,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[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", @@ -1256,7 +1256,7 @@ dependencies = [ "ntapi", "once_cell", "rayon", - "winapi", + "windows", ] [[package]] @@ -1282,9 +1282,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +checksum = "cb797dad5fb5b76fcf519e702f4a589483b5ef06567f160c392832c1f5e44909" dependencies = [ "filetime", "libc", @@ -1481,9 +1481,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "url" @@ -1637,6 +1637,25 @@ 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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index cc7a2e7..678d269 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,4 @@ regex = "1" tar = "0.4" -sysinfo = "0.29" +sysinfo = "0.30" diff --git a/src/disk.rs b/src/disk.rs index 3868037..e146ac8 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -1,8 +1,7 @@ use std::env::current_dir; use std::fs; -use std::str; -use sysinfo::{Disk, DiskExt, System, SystemExt}; +use sysinfo::{Disk, Disks}; use console::Style; use indicatif::DecimalBytes; @@ -10,24 +9,21 @@ use indicatif::DecimalBytes; use log::debug; // Print disks list as a table -// Requires list of disk to be up to date: -// let mut sys: System = System::new(); -// sys.refresh_disks_list(); -// sys.refresh_disks(); -pub fn print_disks(sys: &System) { +pub fn print_disks() { println!( "{0: ^20} | {1: ^30} | {2: ^6} | {3: ^9} | {4: ^10} | {5: ^5} ", "Name", "Mount point", "Type", "Removable", "Avail.", "Empty" ); let red = Style::new().red(); let green = Style::new().green(); - for disk in sys.disks() { + let disks = Disks::new_with_refreshed_list(); + for disk in &disks { let disk_removable = if disk.is_removable() { green.apply_to("Yes") } else { red.apply_to("No") }; - let file_system_str = str::from_utf8(disk.file_system()).unwrap(); + let file_system_str = disk.file_system().to_string_lossy(); let file_system = if file_system_str.eq_ignore_ascii_case("vfat") || file_system_str.eq_ignore_ascii_case("fat32") { @@ -59,11 +55,7 @@ pub fn print_disks(sys: &System) { } // Available disk space in current directory -// Requires list of disk to be up to date: -// let mut sys: System = System::new(); -// sys.refresh_disks_list(); -// sys.refresh_disks(); -pub fn get_current_dir_available_space(sys: &System) -> Option { +pub fn get_current_dir_available_space() -> Option { let cwd_result = current_dir(); if cwd_result.is_err() { debug!( @@ -76,7 +68,8 @@ pub fn get_current_dir_available_space(sys: &System) -> Option { let mut cwd_disk: Option<&Disk> = None; // Lookup disk whose mount point is parent of cwd // In case there are multiple candidates, pick up the "nearest" parent of cwd - for disk in sys.disks() { + let disks = Disks::new_with_refreshed_list(); + for disk in &disks { debug!("Disk {:?}", disk); if cwd.starts_with(disk.mount_point()) && (cwd_disk.is_none() diff --git a/src/main.rs b/src/main.rs index 295ffb2..ce6ed48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,6 @@ use reqwest::Client; use indicatif::{DecimalBytes, MultiProgress}; -use sysinfo::{System, SystemExt}; - mod disk; mod download; mod interact; @@ -124,10 +122,7 @@ async fn main() -> Result<(), Error> { } // Check available disk size - let mut sys: System = System::new(); - sys.refresh_disks_list(); - sys.refresh_disks(); - let disk_space = disk::get_current_dir_available_space(&sys); + let disk_space = disk::get_current_dir_available_space(); if let Some(space) = disk_space { if space < total_update_size { interact::warn(&format!("Not enough space on disk to proceed with download. Available disk space in current directory: {}", @@ -156,10 +151,8 @@ async fn main() -> Result<(), Error> { } // Listing available disks for extraction - sys.refresh_disks_list(); - sys.refresh_disks(); // TODO check destination available space. - disk::print_disks(&sys); + disk::print_disks(); let location = interact::prompt("Location where to extract the update files (IMPORTANT: Should be the root of an EMPTY USB device formatted as FAT32)")?; if !location.is_empty() { extract_location = Some(location);