From 2173ca5b51dc472afb72c4a1d231350bba7443fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 3 Feb 2022 16:26:57 +0100 Subject: [PATCH] add a --clean param --- src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 03bfd9f..a913b99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::path::PathBuf; use actix_web::{middleware, App, HttpServer}; use anyhow::Result; use clap::{App as ClapApp, Arg}; -use log::{info, warn}; +use log::{debug, info, warn}; use std::sync::{Arc, RwLock}; use crate::{common::PKG_VERSION, database::UpEndDatabase}; @@ -66,6 +66,11 @@ fn main() -> Result<()> { .long("no-initial-update") .help("Don't run a database update on start."), ) + .arg( + Arg::with_name("CLEAN") + .long("clean") + .help("Clean up temporary files (e.g. previews) on start."), + ) .arg( Arg::with_name("REINITIALIZE") .long("reinitialize") @@ -104,12 +109,23 @@ fn main() -> Result<()> { let ui_enabled = ui_path.exists() && !matches.is_present("NO_UI"); let browser_enabled = desktop_enabled && !matches.is_present("NO_BROWSER"); + let preview_path = upend.db_path.join("previews"); #[cfg(feature = "previews")] let preview_store = Some(Arc::new(crate::previews::PreviewStore::new( - upend.db_path.join("previews"), + preview_path.clone(), upend.clone(), ))); + if matches.is_present("CLEAN") { + info!("Cleaning temporary directories..."); + if preview_path.exists() { + std::fs::remove_dir_all(&preview_path).unwrap(); + debug!("Removed {preview_path:?}"); + } else { + debug!("No preview path exists, continuing..."); + } + } + #[cfg(not(feature = "previews"))] let preview_store = None;