Copy song #61

Merged
phoenix merged 5 commits from copy_song into song_changes 2025-10-11 18:53:13 +00:00
Showing only changes of commit 43b9c512a1 - Show all commits

View File

@@ -153,6 +153,7 @@ impl Song {
filename
}
/// 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() {
Ok(song_path) => match std::fs::File::create(&song_path) {
@@ -169,4 +170,29 @@ impl Song {
// TODO: Add function to remove file from the filesystem
}
// TODO: Add function to copy song
/// Copies a song using the source song's data
pub fn copy_song(song_source: &Song, song_target: &mut Song) -> Result<(), std::io::Error> {
match song_target.song_path() {
Ok(songpath) => {
let p = std::path::Path::new(&songpath);
if p.exists() {
Err(std::io::Error::other(
"Cannot copy song over to one that already exists",
))
} else {
if song_target.data.is_empty() {
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() {
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
}
Err(err) => Err(err),
}
}