From eac7562b80b9f82d21ab737d1e84ba4f12e472dd Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 22:14:10 +0000 Subject: [PATCH] Coverart remove file (#68) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/68 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/coverart.rs | 15 ++++++++++++++- src/song.rs | 4 +++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b72049e..a044124 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.6.5" +version = "0.6.6" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index a1b9ebd..5778e36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.6.5" +version = "0.6.6" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" diff --git a/src/coverart.rs b/src/coverart.rs index 5444a3e..06ac2fc 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -39,7 +39,20 @@ impl CoverArt { } } - // TODO: Add method to remove from filesystem + /// Removes the coverart from the filesystem + pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> { + let p = std::path::Path::new(&self.path); + if p.exists() { + match std::fs::remove_file(p) { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } else { + Err(std::io::Error::other( + "Cannot delete file that does not exist", + )) + } + } } pub mod io { diff --git a/src/song.rs b/src/song.rs index 7ebc487..230b516 100644 --- a/src/song.rs +++ b/src/song.rs @@ -118,7 +118,9 @@ impl Song { Err(err) => Err(err), } } else { - Ok(()) + Err(std::io::Error::other( + "Cannot delete file that does not exist", + )) } } Err(err) => Err(err),