Remove song #64

Merged
phoenix merged 4 commits from remove_song into song_changes 2025-10-11 19:46:00 +00:00
Showing only changes of commit f05751f50b - Show all commits

View File

@@ -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)
}
}
}
}