From 9a293cdb7f1b4fd08102f4cd7e64ea87911d1f61 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Apr 2025 21:43:25 -0400 Subject: [PATCH] Got it working --- src/meta.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/meta.rs b/src/meta.rs index 182cad9..50840a7 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -119,6 +119,23 @@ mod tests { } } + pub fn copy_file( + source_path: &String, + destination_path: &String, + ) -> Result { + println!("Copying file"); + let src_path = std::path::Path::new(source_path); + let dest_path = std::path::Path::new(destination_path); + + println!("Src: {:?}", src_path); + println!("Dest: {:?}", dest_path); + + match std::fs::copy(src_path, dest_path) { + Ok(bytes) => Ok(bytes), + Err(err) => Err(err), + } + } + pub fn file_exists(directory: &String, filename: &String) -> Result { match path_buf(directory, filename) { Ok(pf) => Ok(pf.exists()), @@ -350,4 +367,62 @@ mod tests { } }; } + + mod set { + use super::*; + + #[test] + fn test_set_title() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + let temp_file = tempfile::tempdir().expect("Could not create test directory"); + let mut test_dir = String::from(temp_file.path().to_str().unwrap()); + // test_dir = String::from("tests/sample_tracks3"); + let test_filename = String::from("track08.flac"); + let new_filepath = test_dir + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Title, &filepath) { + Ok(title) => { + let found = title == "Just roll it"; + assert!(found, "Meta information was not found {:?}", title); + let new_title = String::from("The wind burned her"); + + match set_meta(types::Type::Title, &new_filepath, &new_title) { + Ok(m) => { + assert_eq!( + new_title, m, + "New title does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + } }