Remove song #64
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"josekit",
|
"josekit",
|
||||||
"rand",
|
"rand",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
|
21
src/song.rs
21
src/song.rs
@@ -7,6 +7,7 @@ use crate::constants;
|
|||||||
use crate::init;
|
use crate::init;
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
||||||
|
/// Length of characters of a filename to be generated
|
||||||
const FILENAME_LENGTH: i32 = 16;
|
const FILENAME_LENGTH: i32 = 16;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[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
|
/// Saves the song to the filesystem using the song's data
|
||||||
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
||||||
match self.song_path() {
|
match self.song_path() {
|
||||||
@@ -107,10 +107,25 @@ 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Generates a filename. In order to save a song to the filesystem, the song must have
|
/// Generates a filename. In order to save a song to the filesystem, the song must have
|
||||||
/// a directory and filename
|
/// a directory and filename
|
||||||
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
||||||
|
@@ -120,7 +120,7 @@ mod song_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_save_song_to_filesystem() {
|
fn test_save_song_to_filesystem_and_remove() {
|
||||||
let mut song = song::Song::default();
|
let mut song = song::Song::default();
|
||||||
song.directory = utils::get_tests_directory();
|
song.directory = utils::get_tests_directory();
|
||||||
song.filename = String::from("track02.flac");
|
song.filename = String::from("track02.flac");
|
||||||
@@ -132,7 +132,12 @@ mod song_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match song::io::copy_song(&song, &mut copied_song) {
|
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) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {err:?}")
|
assert!(false, "Error: {err:?}")
|
||||||
}
|
}
|
||||||
@@ -142,7 +147,6 @@ mod song_tests {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod album_tests {
|
mod album_tests {
|
||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use icarus_models::album;
|
use icarus_models::album;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user