use camino::Utf8PathBuf;
use color_eyre::Result;
use episko_lib::{
config::{Config, ConfigHandler},
files::File,
metadata::Metadata,
};
use crate::connect_to_db;
pub async fn remove_manifest(file: &Utf8PathBuf, config_handler: &ConfigHandler) -> Result<()> {
let config = config_handler.load_config()?;
if try_remove_from_db(file, &config).await.is_err() {
eprintln!("WARNING: Unable to remove metadata from cache!");
eprintln!("The file will be deleted anyway...");
}
Metadata::remove_file(file.as_std_path())?;
Ok(())
}
async fn try_remove_from_db(file: &Utf8PathBuf, config: &Config) -> Result<()> {
let db = connect_to_db(config).await?;
Ok(Metadata::from_file(file.as_std_path())?
.remove_from_db(&db)
.await?)
}