From f05751f50b87e313a03aaa20345492f903d7407a Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 15:36:28 -0400 Subject: [PATCH 1/4] Added function to remove song from filesystem --- src/song.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/song.rs b/src/song.rs index 5735ee6..600daa5 100644 --- a/src/song.rs +++ b/src/song.rs @@ -7,6 +7,7 @@ use crate::constants; use crate::init; use crate::types; +/// Length of characters of a filename to be generated const FILENAME_LENGTH: i32 = 16; #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] @@ -92,7 +93,6 @@ impl Song { } } - /// Saves the song to the filesystem using the song's data pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { match self.song_path() { @@ -107,7 +107,29 @@ impl Song { } } - // TODO: Add function to remove file from the filesystem + /// Removes the song from the filesystem + pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> { + match self.song_path() { + Ok(song_path) => { + let p = std::path::Path::new(&song_path); + if p.exists() { + match std::fs::remove_file(&p) { + Ok(_) => { + Ok(()) + } + Err(err) => { + Err(err) + } + } + } else { + Ok(()) + } + } + Err(err) => { + Err(err) + } + } + } } -- 2.43.0 From 37a0ca1d709796e7c920fb806b009e13cf6d17a5 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 15:38:21 -0400 Subject: [PATCH 2/4] Modified test --- tests/tests.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index aeff5fb..a153ecb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -120,7 +120,7 @@ mod song_tests { } #[test] - fn test_save_song_to_filesystem() { + fn test_save_song_to_filesystem_and_remove() { let mut song = song::Song::default(); song.directory = utils::get_tests_directory(); song.filename = String::from("track02.flac"); @@ -132,7 +132,15 @@ mod song_tests { }; match song::io::copy_song(&song, &mut copied_song) { - Ok(_) => {} + Ok(_) => { + match copied_song.remove_from_filesystem() { + Ok(_) => { + } + Err(err) => { + assert!(false, "Error: {err:?}") + } + } + } Err(err) => { assert!(false, "Error: {err:?}") } @@ -142,7 +150,6 @@ mod song_tests { #[cfg(test)] mod album_tests { - use crate::utils; use icarus_models::album; -- 2.43.0 From d9f8ec54282d3163bae3dda41c42a55a69d92533 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 15:38:34 -0400 Subject: [PATCH 3/4] Code cleanup --- src/song.rs | 13 +++---------- tests/tests.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/song.rs b/src/song.rs index 600daa5..183d08b 100644 --- a/src/song.rs +++ b/src/song.rs @@ -114,25 +114,18 @@ impl Song { let p = std::path::Path::new(&song_path); if p.exists() { match std::fs::remove_file(&p) { - Ok(_) => { - Ok(()) - } - Err(err) => { - Err(err) - } + Ok(_) => Ok(()), + Err(err) => Err(err), } } else { Ok(()) } } - Err(err) => { - Err(err) - } + Err(err) => Err(err), } } } - /// Generates a filename. In order to save a song to the filesystem, the song must have /// a directory and filename pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String { diff --git a/tests/tests.rs b/tests/tests.rs index a153ecb..386940b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -132,15 +132,12 @@ mod song_tests { }; match song::io::copy_song(&song, &mut copied_song) { - Ok(_) => { - match copied_song.remove_from_filesystem() { - Ok(_) => { - } - Err(err) => { - assert!(false, "Error: {err:?}") - } + Ok(_) => match copied_song.remove_from_filesystem() { + Ok(_) => {} + Err(err) => { + assert!(false, "Error: {err:?}") } - } + }, Err(err) => { assert!(false, "Error: {err:?}") } -- 2.43.0 From 467c611509d3d483f386a2116c0128eb51517fd6 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 15:40:29 -0400 Subject: [PATCH 4/4] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89c15e7..5bd15fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.6.2" +version = "0.6.3" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 16eb4de..6379891 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.6.2" +version = "0.6.3" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" -- 2.43.0