From 14ab07b9c65502126f0c66c56109f52e06f09ed2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 23 Jul 2025 16:18:07 -0400 Subject: [PATCH 1/3] Added code to cleanup files after parsing --- src/main.rs | 26 +++++++++++++++++++++++++- src/the_rest.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aef13f4..fc54d6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,14 @@ async fn main() -> Result<(), Box> { .await { Ok(_) => { - // TODO: Cleanup files in local filesystem + match cleanup(&song_queue_path, &coverart_queue_path).await { + Ok(_) => { + println!("Successful cleanup"); + } + Err(err) => { + eprintln!("Error: {err:?}"); + } + } } Err(err) => { eprintln!("Error: {err:?}"); @@ -100,6 +107,23 @@ async fn wipe_data_from_queues( } } +async fn cleanup(song_queue_path: &String, coverart_queue_path: &String) -> Result<(), std::io::Error> { + match the_rest::cleanup::clean_song_queue(song_queue_path) { + Ok(_) => { + } + Err(err) => { + eprintln!("Error: Problem cleaning up SongQueue files {err:?}"); + } + } + + match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) { + Ok(_) => { + Ok(()) + } + Err(err) => Err(err) + } +} + async fn is_queue_empty( api_url: &String, ) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> { diff --git a/src/the_rest.rs b/src/the_rest.rs index c806f0f..500e37c 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -123,3 +123,48 @@ pub mod wipe_data { } } } + +pub mod cleanup { + pub fn clean_song_queue(song_queue_path: &String) -> Result<(), std::io::Error> { + let file_path = std::path::Path::new(song_queue_path); + if file_path.exists() { + match std::fs::remove_file(file_path) { + Ok(_) => { + if check_file_existence(song_queue_path) { + Err(std::io::Error::other(String::from("SongQueue file exists after a deletion"))) + } else { + Ok(()) + } + }, + Err(err) => Err(std::io::Error::other(err.to_string())) + } + } else { + Err(std::io::Error::other(String::from("SongQueue file path does not exists"))) + } + } + + pub fn clean_coverart_queue(coverart_queue_path: &String) -> Result<(), std::io::Error> { + let coverart_file_path = std::path::Path::new(coverart_queue_path); + if coverart_file_path.exists() { + match std::fs::remove_file(coverart_file_path) { + Ok(_) => { + if !check_file_existence(coverart_queue_path) { + Ok(()) + } else { + Err(std::io::Error::other(String::from("CoverArt file stil exists"))) + } + }, + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } + } else { + Err(std::io::Error::other(String::from("CoverArt file does not exists"))) + } + } + + fn check_file_existence(file_path: &String) -> bool { + let path = std::path::Path::new(file_path); + path.exists() + } +} -- 2.43.0 From 2b83906cd1c81ebcfb732a6f9b8a96e2110f5e62 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 23 Jul 2025 16:18:49 -0400 Subject: [PATCH 2/3] Code formatting --- src/main.rs | 14 +++++++------- src/the_rest.rs | 24 +++++++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index fc54d6c..9362977 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,20 +107,20 @@ async fn wipe_data_from_queues( } } -async fn cleanup(song_queue_path: &String, coverart_queue_path: &String) -> Result<(), std::io::Error> { +async fn cleanup( + song_queue_path: &String, + coverart_queue_path: &String, +) -> Result<(), std::io::Error> { match the_rest::cleanup::clean_song_queue(song_queue_path) { - Ok(_) => { - } + Ok(_) => {} Err(err) => { eprintln!("Error: Problem cleaning up SongQueue files {err:?}"); } } match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) { - Ok(_) => { - Ok(()) - } - Err(err) => Err(err) + Ok(_) => Ok(()), + Err(err) => Err(err), } } diff --git a/src/the_rest.rs b/src/the_rest.rs index 500e37c..b3f0b2e 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -131,15 +131,19 @@ pub mod cleanup { match std::fs::remove_file(file_path) { Ok(_) => { if check_file_existence(song_queue_path) { - Err(std::io::Error::other(String::from("SongQueue file exists after a deletion"))) + Err(std::io::Error::other(String::from( + "SongQueue file exists after a deletion", + ))) } else { Ok(()) } - }, - Err(err) => Err(std::io::Error::other(err.to_string())) + } + Err(err) => Err(std::io::Error::other(err.to_string())), } } else { - Err(std::io::Error::other(String::from("SongQueue file path does not exists"))) + Err(std::io::Error::other(String::from( + "SongQueue file path does not exists", + ))) } } @@ -151,15 +155,17 @@ pub mod cleanup { if !check_file_existence(coverart_queue_path) { Ok(()) } else { - Err(std::io::Error::other(String::from("CoverArt file stil exists"))) + Err(std::io::Error::other(String::from( + "CoverArt file stil exists", + ))) } - }, - Err(err) => { - Err(std::io::Error::other(err.to_string())) } + Err(err) => Err(std::io::Error::other(err.to_string())), } } else { - Err(std::io::Error::other(String::from("CoverArt file does not exists"))) + Err(std::io::Error::other(String::from( + "CoverArt file does not exists", + ))) } } -- 2.43.0 From 9b332874793c67c4492c17f90fd284d597986463 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 23 Jul 2025 16:19:39 -0400 Subject: [PATCH 3/3] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f7e8b0..553b8e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "songparser" -version = "0.2.3" +version = "0.2.4" dependencies = [ "futures", "icarus_envy", diff --git a/Cargo.toml b/Cargo.toml index 0861cc9..cd5e6fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "songparser" -version = "0.2.3" +version = "0.2.4" edition = "2024" rust-version = "1.88" -- 2.43.0