Compare commits
2 Commits
v0.6.0-60-
...
a867f65a26
Author | SHA1 | Date | |
---|---|---|---|
a867f65a26
|
|||
43b9c512a1
|
28
src/song.rs
28
src/song.rs
@@ -153,6 +153,7 @@ impl Song {
|
|||||||
filename
|
filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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() {
|
||||||
Ok(song_path) => match std::fs::File::create(&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 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -157,29 +157,16 @@ mod song_tests {
|
|||||||
song.directory = utils::get_tests_directory();
|
song.directory = utils::get_tests_directory();
|
||||||
song.filename = String::from("track02.flac");
|
song.filename = String::from("track02.flac");
|
||||||
|
|
||||||
match song.song_path() {
|
let mut copied_song = song::Song {
|
||||||
Ok(song_path) => match utils::extract_data_from_file(&song_path) {
|
directory: utils::get_tests_directory(),
|
||||||
Ok(data) => {
|
filename: String::from("track02-coppied.flac"),
|
||||||
let copied_song = song::Song {
|
..Default::default()
|
||||||
directory: utils::get_tests_directory(),
|
};
|
||||||
filename: String::from("track02-coppied.flac"),
|
|
||||||
data: data,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
match copied_song.save_to_filesystem() {
|
match song::copy_song(&song, &mut copied_song) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {err:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {err:?}")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {err:?}");
|
assert!(false, "Error: {err:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user