add a --clean param

feat/vaults
Tomáš Mládek 2022-02-03 16:26:57 +01:00
parent 2b74aea57d
commit 2173ca5b51
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
1 changed files with 18 additions and 2 deletions

View File

@ -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;