Cleanup
This commit is contained in:
50
src/song.rs
50
src/song.rs
@@ -1,12 +1,12 @@
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::constants;
|
use crate::constants;
|
||||||
use crate::init;
|
use crate::init;
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
||||||
use rand::Rng;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
@@ -170,29 +170,35 @@ impl Song {
|
|||||||
// TODO: Add function to remove file from the filesystem
|
// TODO: Add function to remove file from the filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies a song using the source song's data
|
/// I/O operations for songs
|
||||||
pub fn copy_song(song_source: &Song, song_target: &mut Song) -> Result<(), std::io::Error> {
|
pub mod io {
|
||||||
match song_target.song_path() {
|
/// Copies a song using the source song's data
|
||||||
Ok(songpath) => {
|
pub fn copy_song(
|
||||||
let p = std::path::Path::new(&songpath);
|
song_source: &super::Song,
|
||||||
if p.exists() {
|
song_target: &mut super::Song,
|
||||||
Err(std::io::Error::other(
|
) -> Result<(), std::io::Error> {
|
||||||
"Cannot copy song over to one that already exists",
|
match song_target.song_path() {
|
||||||
))
|
Ok(songpath) => {
|
||||||
} else {
|
let p = std::path::Path::new(&songpath);
|
||||||
if song_target.data.is_empty() {
|
if p.exists() {
|
||||||
song_target.data = song_source.data.clone();
|
Err(std::io::Error::other(
|
||||||
|
"Cannot copy song over to one that already exists",
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
song_target.data.clear();
|
if song_target.data.is_empty() {
|
||||||
song_target.data = song_source.data.clone();
|
song_target.data = song_source.data.clone();
|
||||||
}
|
} else {
|
||||||
|
song_target.data.clear();
|
||||||
|
song_target.data = song_source.data.clone();
|
||||||
|
}
|
||||||
|
|
||||||
match song_target.save_to_filesystem() {
|
match song_target.save_to_filesystem() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user