From 7e50c30e063293ed1520e7f4b2dc131e438bb86e Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Oct 2025 15:56:50 -0400 Subject: [PATCH 1/5] tsk-45: Added root directory check --- src/config.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 19 ++++++++----------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8f07e8c..fa2a2a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,4 +3,34 @@ pub struct App { pub uri: String, pub auth_uri: String, pub token: icarus_models::login_result::LoginResult, + pub root_directory: String +} + +impl App { + pub fn does_root_directory_exists(&self) -> bool { + let path = std::path::Path::new(&self.root_directory); + if path.exists() { + if path.is_dir() { + true + } else { + false + } + } else { + false + } + } +} + + +pub async fn initialize_app_config() -> App { + App { + uri: icarus_envy::environment::get_icarus_base_api_url() + .await + .value, + auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url() + .await + .value, + root_directory: icarus_envy::environment::get_root_directory().await.value, + ..Default::default() + } } diff --git a/src/main.rs b/src/main.rs index 3b4635b..55a7c22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,21 +11,18 @@ pub const SECONDS_TO_SLEEP: u64 = 5; #[tokio::main] async fn main() -> Result<(), Box> { - let mut app = config::App { - uri: icarus_envy::environment::get_icarus_base_api_url() - .await - .value, - auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url() - .await - .value, - ..Default::default() - }; + let mut app = config::initialize_app_config().await; println!("Base URL: {:?}", app.uri); println!("Auth URL: {:?}", app.auth_uri); - match auth::get_token(&app).await { + if !app.does_root_directory_exists() { + eprintln!("Root directory does not exist"); + std::process::exit(-1); + } + + app.token = match auth::get_token(&app).await { Ok(login_result) => { - app.token = login_result; + login_result } Err(err) => { eprintln!("Error: {err:?}"); -- 2.43.0 From ae8aaad068828a1406f366940ff2e6bb9502d5cf Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Oct 2025 15:57:17 -0400 Subject: [PATCH 2/5] tsk-45: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39efe91..e67cdc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1322,7 +1322,7 @@ dependencies = [ [[package]] name = "songparser" -version = "0.4.8" +version = "0.4.9" dependencies = [ "futures", "icarus_envy", diff --git a/Cargo.toml b/Cargo.toml index e84cf61..4722650 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "songparser" -version = "0.4.8" +version = "0.4.9" edition = "2024" rust-version = "1.90" -- 2.43.0 From cd6ee65318f01e168cd1643907420dd1d85da111 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Oct 2025 16:06:24 -0400 Subject: [PATCH 3/5] tsk-45: Added more checks --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 55a7c22..d48245a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,17 @@ async fn main() -> Result<(), Box> { if !app.does_root_directory_exists() { eprintln!("Root directory does not exist"); - std::process::exit(-1); + println!("Attempting to create directory"); + let path = std::path::Path::new(&app.root_directory); + match std::fs::create_dir(&path) { + Ok(_) => { + println!("Directory created"); + } + Err(err) => { + eprintln!("Error creating directory: {err:?}"); + std::process::exit(-1); + } + } } app.token = match auth::get_token(&app).await { -- 2.43.0 From c79a2cf98eafa16b31a6048d4eb9ca0480d0c90f Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Oct 2025 16:06:50 -0400 Subject: [PATCH 4/5] tsk-45: Code formatting --- src/config.rs | 9 ++------- src/main.rs | 4 +--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index fa2a2a6..d316495 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,25 +3,20 @@ pub struct App { pub uri: String, pub auth_uri: String, pub token: icarus_models::login_result::LoginResult, - pub root_directory: String + pub root_directory: String, } impl App { pub fn does_root_directory_exists(&self) -> bool { let path = std::path::Path::new(&self.root_directory); if path.exists() { - if path.is_dir() { - true - } else { - false - } + if path.is_dir() { true } else { false } } else { false } } } - pub async fn initialize_app_config() -> App { App { uri: icarus_envy::environment::get_icarus_base_api_url() diff --git a/src/main.rs b/src/main.rs index d48245a..b5de943 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,9 +31,7 @@ async fn main() -> Result<(), Box> { } app.token = match auth::get_token(&app).await { - Ok(login_result) => { - login_result - } + Ok(login_result) => login_result, Err(err) => { eprintln!("Error: {err:?}"); std::process::exit(-1); -- 2.43.0 From 11332b58a12f1f27d3732c3197758cb131f4863f Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Oct 2025 16:12:21 -0400 Subject: [PATCH 5/5] tsk-45: Warning fix --- src/config.rs | 6 +----- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index d316495..760d951 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,11 +9,7 @@ pub struct App { impl App { pub fn does_root_directory_exists(&self) -> bool { let path = std::path::Path::new(&self.root_directory); - if path.exists() { - if path.is_dir() { true } else { false } - } else { - false - } + if path.exists() { path.is_dir() } else { false } } } diff --git a/src/main.rs b/src/main.rs index b5de943..0614ab5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ async fn main() -> Result<(), Box> { eprintln!("Root directory does not exist"); println!("Attempting to create directory"); let path = std::path::Path::new(&app.root_directory); - match std::fs::create_dir(&path) { + match std::fs::create_dir(path) { Ok(_) => { println!("Directory created"); } -- 2.43.0