From 823fc2a7f2ad5fd822c9a408878ee2ff3615e6da Mon Sep 17 00:00:00 2001 From: Max Winter Date: Thu, 18 Jan 2024 14:34:47 +0100 Subject: [PATCH 1/7] added flash command to cli --- cli/src/flash.rs | 20 ++++++++++++++++++++ cli/src/main.rs | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 cli/src/flash.rs diff --git a/cli/src/flash.rs b/cli/src/flash.rs new file mode 100644 index 0000000..89a3c33 --- /dev/null +++ b/cli/src/flash.rs @@ -0,0 +1,20 @@ +use std::path::PathBuf; +use clap::Parser; + +#[derive(Parser, Debug)] +#[clap(about = "This command flashes a SD card or USB mass storage with the selected version of the hydrophonitor system.")] +pub struct Flash { + ///Path to USB mass storage or SD card where the NixOS image will be flashed. + #[clap(short, long)] + device: Option, + + /// Path to the image that will be flashed to the device. + #[clap(short, long)] + image: Option, +} + +impl Flash { + pub fn flash(&mut self) { + println!("Flashing device {:?} with image {:?}", &self.device, &self.image); + } +} diff --git a/cli/src/main.rs b/cli/src/main.rs index bebdcf8..4626e67 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -3,16 +3,19 @@ use clap_verbosity_flag::Verbosity; use crate::clean::Clean; use crate::import::Import; +use crate::flash::Flash; mod import; mod clean; mod connect; +mod flash; #[derive(Subcommand)] #[clap(about = "A tool to record audio on Linux using the command line.")] pub enum Commands { Import(Import), Clean(Clean), + Flash(Flash), } @@ -36,6 +39,7 @@ fn main() { match commands { Commands::Import(mut import) => import.import(), Commands::Clean(mut clean) => clean.clean(), + Commands::Flash(mut flash) => flash.flash(), } } From 936a41bead68b3937a302cce4c905f7940bb8d7f Mon Sep 17 00:00:00 2001 From: Max Winter Date: Thu, 18 Jan 2024 14:42:56 +0100 Subject: [PATCH 2/7] integrated connect wizard --- cli/src/flash.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cli/src/flash.rs b/cli/src/flash.rs index 89a3c33..0141d1b 100644 --- a/cli/src/flash.rs +++ b/cli/src/flash.rs @@ -1,6 +1,11 @@ use std::path::PathBuf; + use clap::Parser; +use hydrophonitor_lib::connect; + +use crate::connect::connect; + #[derive(Parser, Debug)] #[clap(about = "This command flashes a SD card or USB mass storage with the selected version of the hydrophonitor system.")] pub struct Flash { @@ -9,12 +14,21 @@ pub struct Flash { device: Option, /// Path to the image that will be flashed to the device. - #[clap(short, long)] - image: Option, + #[clap(short, long, required = true)] + image: PathBuf, } impl Flash { pub fn flash(&mut self) { - println!("Flashing device {:?} with image {:?}", &self.device, &self.image); + let _mount; + let device_path; + match &self.device { + Some(device) => device_path = device, + None => { + _mount = connect(); + device_path = &connect::MOUNT_PATH; + } + } + println!("Flashing device {:?} with image {:?}", device_path, &self.image); } } From 6aeeeca6db6f2798479dd437e72a62a74adda915 Mon Sep 17 00:00:00 2001 From: Max Winter Date: Wed, 20 Mar 2024 12:33:34 +0100 Subject: [PATCH 3/7] wip: implementing flash functionality; changed connect wizard to take device type as parameter Signed-off-by: Max Winter --- cli/src/clean.rs | 3 ++- cli/src/connect.rs | 17 +++++++++++------ cli/src/flash.rs | 16 +++++++++++++--- lib/src/connect.rs | 18 +++++++++--------- lib/src/device_type.rs | 13 +++++++++++++ lib/src/flash.rs | 25 +++++++++++++++++++++++++ lib/src/lib.rs | 4 +++- 7 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 lib/src/device_type.rs create mode 100644 lib/src/flash.rs diff --git a/cli/src/clean.rs b/cli/src/clean.rs index 392b123..5941900 100644 --- a/cli/src/clean.rs +++ b/cli/src/clean.rs @@ -5,6 +5,7 @@ use clap::Parser; use log::info; use hydrophonitor_lib::{clean as clean_lib, connect}; +use hydrophonitor_lib::device_type::DeviceType; use crate::connect::connect; @@ -24,7 +25,7 @@ impl Clean { match &self.device { Some(device) => output_dir = device.clone(), None => { - _mount = connect(); + _mount = connect(DeviceType::Part); output_dir = connect::MOUNT_PATH.clone(); } } diff --git a/cli/src/connect.rs b/cli/src/connect.rs index 4a0eac1..a3710b3 100644 --- a/cli/src/connect.rs +++ b/cli/src/connect.rs @@ -4,10 +4,14 @@ use dialoguer::Select; use sys_mount::{Mount, UnmountDrop}; use hydrophonitor_lib::connect as connect_lib; +use hydrophonitor_lib::device_type::DeviceType; -//Runs the connect wizard to select and mount the hydrophonitor device. It returns a mount object that defines the lifetime of the mount. -pub fn connect() -> UnmountDrop { - let devices = connect_lib::get_device_list(); + +// Runs the connect wizard to select and mount the hydrophonitor device. +// The device type specifies which type of devices which should be listed. +// It returns a mount object that defines the lifetime of the mount. +pub fn connect(device_type: DeviceType) -> UnmountDrop { + let devices = connect_lib::get_device_list(device_type); let mut selected_device = &String::new(); match connect_lib::find_suitable_device(&devices) { Some(dev) => { @@ -28,14 +32,15 @@ pub fn connect() -> UnmountDrop { let mount = connect_lib::mount_device(selected_device); println!("successfully connected to device {selected_device}!"); - return mount; + mount } -fn manual_connect(devices: &Vec) -> &String { +fn manual_connect(devices: &[String]) -> &String { let selection = Select::new() .with_prompt("Please choose a device from the list:") - .items(&devices) + .items(devices) .default(0) .interact(); &devices[selection.unwrap_or_default()] + //TODO security question } \ No newline at end of file diff --git a/cli/src/flash.rs b/cli/src/flash.rs index 0141d1b..d24dbb4 100644 --- a/cli/src/flash.rs +++ b/cli/src/flash.rs @@ -1,13 +1,16 @@ use std::path::PathBuf; use clap::Parser; +use log::error; use hydrophonitor_lib::connect; +use hydrophonitor_lib::device_type::DeviceType; +use hydrophonitor_lib::flash as flash_lib; use crate::connect::connect; #[derive(Parser, Debug)] -#[clap(about = "This command flashes a SD card or USB mass storage with the selected version of the hydrophonitor system.")] +#[clap(about = "This command flashes a SD card or USB mass storage with the selected version of the Hydrophonitor system.")] pub struct Flash { ///Path to USB mass storage or SD card where the NixOS image will be flashed. #[clap(short, long)] @@ -25,10 +28,17 @@ impl Flash { match &self.device { Some(device) => device_path = device, None => { - _mount = connect(); + _mount = connect(DeviceType::Disk); device_path = &connect::MOUNT_PATH; } } - println!("Flashing device {:?} with image {:?}", device_path, &self.image); + println!("Flashing device {:?} with image {:?}, this may take a while...", device_path, &self.image); + flash_lib::flash(&self.image, device_path).unwrap_or_else(|err| { + error!("Error: {}", err); + std::process::exit(1); + }); + println!("Flashing finished!"); } } + + diff --git a/lib/src/connect.rs b/lib/src/connect.rs index 8abc711..a5530ab 100644 --- a/lib/src/connect.rs +++ b/lib/src/connect.rs @@ -7,13 +7,15 @@ use lazy_static::lazy_static; use log::debug; use sys_mount::{Mount, unmount, UnmountDrop, UnmountFlags}; +use crate::device_type::DeviceType; + lazy_static! { pub static ref MOUNT_PATH: PathBuf = PathBuf::from("/var/lib/hydrophonitor/device"); static ref TEMP_MOUNT_PATH: PathBuf = PathBuf::from("/var/lib/hydrophonitor/temp_device"); } //gets all available devices with lsblk -pub fn get_device_list() -> Vec { +pub fn get_device_list(device_type: DeviceType) -> Vec { let output = Command::new("lsblk").arg("-l").output().expect("Failed to run lsblk!"); let output = String::from_utf8_lossy(&output.stdout); let devices: Vec<&str> = output.lines().collect(); @@ -21,8 +23,8 @@ pub fn get_device_list() -> Vec { for device in devices.iter() { let mut device_columns = device.split_whitespace(); let cropped_device = device_columns.next().unwrap_or_default().to_string(); - let device_type = device_columns.nth(4); - if device_type.unwrap_or_default() == "part" { + let actual_device_type = device_columns.nth(4); + if actual_device_type.unwrap_or_default() == device_type.as_str() { devices_cropped.push(cropped_device); } } @@ -40,9 +42,8 @@ pub fn find_suitable_device(devices: &Vec) -> Option<&String> { Ok(_) => { let read_dir_result = fs::read_dir(format!("{}/output", TEMP_MOUNT_PATH.to_str().unwrap())); - match read_dir_result { - Ok(_) => return Some(device), - Err(_) => {} + if read_dir_result.is_ok() { + return Some(device); } } Err(e) => { @@ -58,9 +59,8 @@ pub fn find_suitable_device(devices: &Vec) -> Option<&String> { } pub fn mount_device(device: &String) -> UnmountDrop { - match unmount(&*MOUNT_PATH, UnmountFlags::empty()) { - Ok(_) => debug!("unmounting previously mounted device at {:?}", &*MOUNT_PATH), - Err(_) => {} + if unmount(&*MOUNT_PATH, UnmountFlags::empty()).is_ok() { + debug!("unmounting previously mounted device at {:?}", &*MOUNT_PATH) } create_dir_if_not_existing(&*MOUNT_PATH); diff --git a/lib/src/device_type.rs b/lib/src/device_type.rs new file mode 100644 index 0000000..24f6fd1 --- /dev/null +++ b/lib/src/device_type.rs @@ -0,0 +1,13 @@ +pub enum DeviceType { + Part, + Disk, +} + +impl DeviceType { + pub fn as_str(&self) -> &str{ + match self { + DeviceType::Disk => "disk", + DeviceType::Part => "part", + } + } +} \ No newline at end of file diff --git a/lib/src/flash.rs b/lib/src/flash.rs new file mode 100644 index 0000000..420469c --- /dev/null +++ b/lib/src/flash.rs @@ -0,0 +1,25 @@ +use std::error::Error; +use std::fs::File; +use std::io::{Read, Write}; +use std::path::PathBuf; + +pub fn flash(image_path: &PathBuf, device_path: &PathBuf) -> Result<(), Box> { + // Open source file for reading + let mut source_file = File::open(image_path).expect(&*format!("Failed to open image {:?}!", image_path)); + + // Open destination file for writing + let mut dest_file = File::open(device_path).expect(&*format!("Failed to open device file {:?}!", device_path)); + + // Set buffer size for read and write operations + let mut buffer = [0; 4096]; // Adjust the buffer size as needed + + // Read data from source and write to destination + loop { + let bytes_read = source_file.read(&mut buffer).expect("Failed to read bytes from image!"); + if bytes_read == 0 { + // Reached end of file + return Ok(()); + } + dest_file.write_all(&buffer[..bytes_read]).expect("Failed to write bytes to device!"); + } +} diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 36e298a..5aace91 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,3 +1,5 @@ pub mod import; pub mod clean; -pub mod connect; \ No newline at end of file +pub mod connect; +pub mod flash; +pub mod device_type; \ No newline at end of file From 48b3276a8bfcbfc1c203ec308a5e24c8ecd5ef7a Mon Sep 17 00:00:00 2001 From: Max Winter Date: Wed, 20 Mar 2024 14:50:23 +0100 Subject: [PATCH 4/7] flash command is now working Signed-off-by: Max Winter --- cli/src/clean.rs | 3 +-- cli/src/connect.rs | 7 +++---- cli/src/flash.rs | 25 ++++++++++++------------- lib/src/flash.rs | 11 ++++++++++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/cli/src/clean.rs b/cli/src/clean.rs index 5941900..392b123 100644 --- a/cli/src/clean.rs +++ b/cli/src/clean.rs @@ -5,7 +5,6 @@ use clap::Parser; use log::info; use hydrophonitor_lib::{clean as clean_lib, connect}; -use hydrophonitor_lib::device_type::DeviceType; use crate::connect::connect; @@ -25,7 +24,7 @@ impl Clean { match &self.device { Some(device) => output_dir = device.clone(), None => { - _mount = connect(DeviceType::Part); + _mount = connect(); output_dir = connect::MOUNT_PATH.clone(); } } diff --git a/cli/src/connect.rs b/cli/src/connect.rs index a3710b3..416cc67 100644 --- a/cli/src/connect.rs +++ b/cli/src/connect.rs @@ -6,12 +6,11 @@ use sys_mount::{Mount, UnmountDrop}; use hydrophonitor_lib::connect as connect_lib; use hydrophonitor_lib::device_type::DeviceType; - // Runs the connect wizard to select and mount the hydrophonitor device. // The device type specifies which type of devices which should be listed. // It returns a mount object that defines the lifetime of the mount. -pub fn connect(device_type: DeviceType) -> UnmountDrop { - let devices = connect_lib::get_device_list(device_type); +pub fn connect() -> UnmountDrop { + let devices = connect_lib::get_device_list(DeviceType::Part); let mut selected_device = &String::new(); match connect_lib::find_suitable_device(&devices) { Some(dev) => { @@ -35,7 +34,7 @@ pub fn connect(device_type: DeviceType) -> UnmountDrop { mount } -fn manual_connect(devices: &[String]) -> &String { +pub(crate) fn manual_connect(devices: &[String]) -> &String { let selection = Select::new() .with_prompt("Please choose a device from the list:") .items(devices) diff --git a/cli/src/flash.rs b/cli/src/flash.rs index d24dbb4..44f1db2 100644 --- a/cli/src/flash.rs +++ b/cli/src/flash.rs @@ -3,12 +3,10 @@ use std::path::PathBuf; use clap::Parser; use log::error; -use hydrophonitor_lib::connect; +use hydrophonitor_lib::connect as connect_lib; use hydrophonitor_lib::device_type::DeviceType; use hydrophonitor_lib::flash as flash_lib; -use crate::connect::connect; - #[derive(Parser, Debug)] #[clap(about = "This command flashes a SD card or USB mass storage with the selected version of the Hydrophonitor system.")] pub struct Flash { @@ -23,17 +21,12 @@ pub struct Flash { impl Flash { pub fn flash(&mut self) { - let _mount; - let device_path; - match &self.device { - Some(device) => device_path = device, - None => { - _mount = connect(DeviceType::Disk); - device_path = &connect::MOUNT_PATH; - } - } + let device_path = match &self.device { + Some(device) => device.clone(), + None => select_device() + }; println!("Flashing device {:?} with image {:?}, this may take a while...", device_path, &self.image); - flash_lib::flash(&self.image, device_path).unwrap_or_else(|err| { + flash_lib::flash(&self.image, &device_path).unwrap_or_else(|err| { error!("Error: {}", err); std::process::exit(1); }); @@ -41,4 +34,10 @@ impl Flash { } } +fn select_device() -> PathBuf { + let devices = connect_lib::get_device_list(DeviceType::Disk); + let selected_device = crate::connect::manual_connect(&devices); + PathBuf::from(format!("/dev/{selected_device}")) +} + diff --git a/lib/src/flash.rs b/lib/src/flash.rs index 420469c..2a3dd90 100644 --- a/lib/src/flash.rs +++ b/lib/src/flash.rs @@ -4,11 +4,20 @@ use std::io::{Read, Write}; use std::path::PathBuf; pub fn flash(image_path: &PathBuf, device_path: &PathBuf) -> Result<(), Box> { + /* + let output = Command::new("dd") + .arg(&*format!("if={image_path:?}")) + .arg(&*format!("of={device_path:?}")) + .arg("bs=4M") + .output() + .expect("Failed to run dd!"); + */ + // Open source file for reading let mut source_file = File::open(image_path).expect(&*format!("Failed to open image {:?}!", image_path)); // Open destination file for writing - let mut dest_file = File::open(device_path).expect(&*format!("Failed to open device file {:?}!", device_path)); + let mut dest_file = File::create(device_path).expect(&*format!("Failed to open device file {:?}!", device_path)); // Set buffer size for read and write operations let mut buffer = [0; 4096]; // Adjust the buffer size as needed From 086f999e4f3831320eb5c562f23d4e485c213a29 Mon Sep 17 00:00:00 2001 From: Max Winter Date: Wed, 20 Mar 2024 15:15:07 +0100 Subject: [PATCH 5/7] flash command: added confirmation question and did some refactoring Signed-off-by: Max Winter --- cli/src/connect.rs | 1 - cli/src/flash.rs | 31 ++++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cli/src/connect.rs b/cli/src/connect.rs index 416cc67..bab1516 100644 --- a/cli/src/connect.rs +++ b/cli/src/connect.rs @@ -41,5 +41,4 @@ pub(crate) fn manual_connect(devices: &[String]) -> &String { .default(0) .interact(); &devices[selection.unwrap_or_default()] - //TODO security question } \ No newline at end of file diff --git a/cli/src/flash.rs b/cli/src/flash.rs index 44f1db2..6505495 100644 --- a/cli/src/flash.rs +++ b/cli/src/flash.rs @@ -1,7 +1,7 @@ +use std::io; use std::path::PathBuf; use clap::Parser; -use log::error; use hydrophonitor_lib::connect as connect_lib; use hydrophonitor_lib::device_type::DeviceType; @@ -25,12 +25,29 @@ impl Flash { Some(device) => device.clone(), None => select_device() }; - println!("Flashing device {:?} with image {:?}, this may take a while...", device_path, &self.image); - flash_lib::flash(&self.image, &device_path).unwrap_or_else(|err| { - error!("Error: {}", err); - std::process::exit(1); - }); - println!("Flashing finished!"); + + //Confirmation question + println!("Do you really want to flash the Hydrophonitor OS to the device {device_path:?}? All data on this device will be lost!"); + let mut user_input = String::new(); + io::stdin().read_line(&mut user_input).expect("Failed to read line!"); + match user_input.trim().to_lowercase().as_str() { + "y" | "yes" => (), + "n" | "no" => { + println!("Aborting!"); + return; + } + _ => { + println!("Invalid response. Please enter 'y' or 'n'."); + return; + } + } + + //Flashing + println!("Flashing device {:?} with image {:?}, this may take a while...", &device_path, &self.image); + match flash_lib::flash(&self.image, &device_path) { + Ok(_) => println!("Flashing finished!"), + Err(err) => println!("Flashing failed due to error: {}, aborting!", err), + }; } } From a96ae73b867f20caeb8943e93b4afbcb81e04376 Mon Sep 17 00:00:00 2001 From: Max Winter Date: Thu, 21 Mar 2024 16:18:07 +0100 Subject: [PATCH 6/7] flash command: changed confirmation question to use dialoguer; changed error handling to pass errors to the top level --- cli/src/connect.rs | 2 +- cli/src/flash.rs | 40 ++++++++++++++++------------------------ cli/src/main.rs | 2 +- lib/src/flash.rs | 22 +++------------------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/cli/src/connect.rs b/cli/src/connect.rs index c0d6928..16bb468 100644 --- a/cli/src/connect.rs +++ b/cli/src/connect.rs @@ -32,7 +32,7 @@ pub fn connect() -> Result> { Ok(mount) } -fn manual_connect(devices: &[String]) -> &String { +pub(crate) fn manual_connect(devices: &[String]) -> &String { let selection = Select::new() .with_prompt("Please choose a device from the list:") .items(devices) diff --git a/cli/src/flash.rs b/cli/src/flash.rs index 1f08d4d..eb197f9 100644 --- a/cli/src/flash.rs +++ b/cli/src/flash.rs @@ -1,7 +1,8 @@ -use std::io; use std::path::PathBuf; +use anyhow::{Context, Result}; use clap::Parser; +use dialoguer::Confirm; use hydrophonitor_lib::connect as connect_lib; use hydrophonitor_lib::device_type::DeviceType; @@ -20,42 +21,33 @@ pub struct Flash { } impl Flash { - pub fn flash(&mut self) { + pub fn flash(&mut self) -> Result<()> { let device_path = match &self.device { Some(device) => device.clone(), - None => select_device() + None => select_device().with_context(|| "Failed to select device")? }; - //TODO change to use dialoguer //Confirmation question - println!("Do you really want to flash the Hydrophonitor OS to the device {device_path:?}? All data on this device will be lost!"); - let mut user_input = String::new(); - io::stdin().read_line(&mut user_input).expect("Failed to read line!"); - match user_input.trim().to_lowercase().as_str() { - "y" | "yes" => (), - "n" | "no" => { - println!("Aborting!"); - return; - } - _ => { - println!("Invalid response. Please enter 'y' or 'n'."); - return; - } + let use_device = Confirm::new() + .with_prompt(format!("Do you really want to flash the Hydrophonitor OS to the device {device_path:?}? All data on this device will be lost!")) + .default(true) + .interact()?; + if !use_device { + println!("Aborting!"); + return Ok(()); } //Flashing println!("Flashing device {:?} with image {:?}, this may take a while...", &device_path, &self.image); - match flash_lib::flash(&self.image, &device_path) { - Ok(_) => println!("Flashing finished!"), - Err(err) => println!("Flashing failed due to error: {}, aborting!", err), - }; + flash_lib::flash(&self.image, &device_path).with_context(|| "Flashing device failed")?; + Ok(()) } } -fn select_device() -> PathBuf { - let devices = connect_lib::get_device_list(DeviceType::Disk); +fn select_device() -> Result { + let devices = connect_lib::get_device_list(DeviceType::Disk).with_context(|| "Failed to get device list")?; let selected_device = crate::connect::manual_connect(&devices); - PathBuf::from(format!("/dev/{selected_device}")) + Ok(PathBuf::from(format!("/dev/{selected_device}"))) } diff --git a/cli/src/main.rs b/cli/src/main.rs index bbebb49..132ff0a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -39,7 +39,7 @@ fn main() { let result = match commands { Commands::Import(mut import) => import.import(), Commands::Clean(mut clean) => clean.clean(), - Commands::Flash(mut flash) => Ok(flash.flash()), //TODO adjust result from flash to match new error handling + Commands::Flash(mut flash) => flash.flash(), }; if let Err(err) = result { diff --git a/lib/src/flash.rs b/lib/src/flash.rs index 2a3dd90..de14c35 100644 --- a/lib/src/flash.rs +++ b/lib/src/flash.rs @@ -1,32 +1,16 @@ -use std::error::Error; use std::fs::File; use std::io::{Read, Write}; use std::path::PathBuf; -pub fn flash(image_path: &PathBuf, device_path: &PathBuf) -> Result<(), Box> { - /* - let output = Command::new("dd") - .arg(&*format!("if={image_path:?}")) - .arg(&*format!("of={device_path:?}")) - .arg("bs=4M") - .output() - .expect("Failed to run dd!"); - */ +use anyhow::Result; - // Open source file for reading +pub fn flash(image_path: &PathBuf, device_path: &PathBuf) -> Result<()> { let mut source_file = File::open(image_path).expect(&*format!("Failed to open image {:?}!", image_path)); - - // Open destination file for writing let mut dest_file = File::create(device_path).expect(&*format!("Failed to open device file {:?}!", device_path)); - - // Set buffer size for read and write operations - let mut buffer = [0; 4096]; // Adjust the buffer size as needed - - // Read data from source and write to destination + let mut buffer = [0; 4096]; loop { let bytes_read = source_file.read(&mut buffer).expect("Failed to read bytes from image!"); if bytes_read == 0 { - // Reached end of file return Ok(()); } dest_file.write_all(&buffer[..bytes_read]).expect("Failed to write bytes to device!"); From a5c11b96197fc1c98e71d56ac831c88b4d165a1b Mon Sep 17 00:00:00 2001 From: Max Winter Date: Tue, 26 Mar 2024 15:26:34 +0100 Subject: [PATCH 7/7] refactoring Signed-off-by: Max Winter --- lib/src/clean.rs | 4 ++-- lib/src/device_type.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/clean.rs b/lib/src/clean.rs index d385388..f16c8e3 100644 --- a/lib/src/clean.rs +++ b/lib/src/clean.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::PathBuf; -use anyhow::{Context, Error}; +use anyhow::{Context, Result}; use log::warn; pub fn get_deployments_of_device(output_dir: &PathBuf) -> Option> { @@ -21,7 +21,7 @@ pub fn get_deployments_of_device(output_dir: &PathBuf) -> Option> { } } -pub fn clear_directory(output_dir: &PathBuf) -> Result<(), Error> { +pub fn clear_directory(output_dir: &PathBuf) -> Result<()> { fs::remove_dir_all(output_dir).with_context(|| format!("Removing everything in directory {:?} failed", &output_dir))?; fs::create_dir(output_dir).with_context(|| format!("Creating new empty output directory in {:?} failed", &output_dir))?; Ok(()) diff --git a/lib/src/device_type.rs b/lib/src/device_type.rs index 24f6fd1..56dec2e 100644 --- a/lib/src/device_type.rs +++ b/lib/src/device_type.rs @@ -1,3 +1,4 @@ +// Is used to select which devices of which type should be shown in the connect wizard. pub enum DeviceType { Part, Disk,