From bac13f485375907fbfba88ce5fdba86dad5e1f15 Mon Sep 17 00:00:00 2001 From: trivernis Date: Fri, 5 Nov 2021 22:21:01 +0100 Subject: [PATCH] Fix issue with default paths on init Signed-off-by: trivernis --- mediarepo-daemon/src/constants.rs | 2 ++ mediarepo-daemon/src/main.rs | 23 ++++++++++++++--------- mediarepo-daemon/src/utils.rs | 11 ++++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mediarepo-daemon/src/constants.rs b/mediarepo-daemon/src/constants.rs index a42a0f8..c8bd4c7 100644 --- a/mediarepo-daemon/src/constants.rs +++ b/mediarepo-daemon/src/constants.rs @@ -1,3 +1,5 @@ pub static SETTINGS_PATH: &str = "./repo.toml"; pub static DEFAULT_STORAGE_NAME: &str = "Main"; +pub static DEFAULT_STORAGE_PATH: &str = "files"; pub static THUMBNAIL_STORAGE_NAME: &str = "Thumbnails"; +pub static THUMBNAIL_STORAGE_PATH: &str = "./thumbnails"; diff --git a/mediarepo-daemon/src/main.rs b/mediarepo-daemon/src/main.rs index 1b01a58..314454c 100644 --- a/mediarepo-daemon/src/main.rs +++ b/mediarepo-daemon/src/main.rs @@ -18,7 +18,10 @@ use mediarepo_socket::get_builder; use num_integer::Integer; use std::env; -use crate::constants::{DEFAULT_STORAGE_NAME, SETTINGS_PATH, THUMBNAIL_STORAGE_NAME}; +use crate::constants::{ + DEFAULT_STORAGE_NAME, DEFAULT_STORAGE_PATH, SETTINGS_PATH, THUMBNAIL_STORAGE_NAME, + THUMBNAIL_STORAGE_PATH, +}; use crate::utils::{create_paths_for_repo, get_repo, load_settings}; mod constants; @@ -140,24 +143,26 @@ async fn init(opt: Opt, force: bool) -> RepoResult<()> { } let settings = Settings::default(); log::debug!("Creating paths"); - create_paths_for_repo(&opt.repo, &settings).await?; + create_paths_for_repo( + &opt.repo, + &settings, + DEFAULT_STORAGE_PATH, + THUMBNAIL_STORAGE_PATH, + ) + .await?; let db_path = opt.repo.join(&settings.database_path); if db_path.exists() { panic!("Database already exists in location. Use --force with init to delete everything and start a new repository"); } log::debug!("Creating repo"); let repo = get_repo(&db_path.to_str().unwrap()).await?; - let storage_path = opt - .repo - .join(&settings.default_file_store) - .canonicalize() - .unwrap(); + let storage_path = opt.repo.join(DEFAULT_STORAGE_PATH).canonicalize().unwrap(); log::debug!("Adding storage"); repo.add_storage(DEFAULT_STORAGE_NAME, storage_path.to_str().unwrap()) .await?; let thumb_storage_path = opt .repo - .join(&settings.thumbnail_store) + .join(THUMBNAIL_STORAGE_PATH) .canonicalize() .unwrap(); repo.add_storage(THUMBNAIL_STORAGE_NAME, thumb_storage_path.to_str().unwrap()) @@ -240,7 +245,7 @@ async fn add_tags_from_tags_file( .find(|t| if let (Some(ns1), Some(ns2)) = (t.namespace(), &tag.0) { *ns1.name() == *ns2 } else { false } && *t.name() == *tag.1) - .is_some() + .is_none() }); let mut tag_ids: Vec = resolved_tags.into_iter().map(|t| t.id()).collect(); diff --git a/mediarepo-daemon/src/utils.rs b/mediarepo-daemon/src/utils.rs index 66c0435..ce0d73e 100644 --- a/mediarepo-daemon/src/utils.rs +++ b/mediarepo-daemon/src/utils.rs @@ -14,7 +14,12 @@ pub async fn get_repo(db_path: &str) -> RepoResult { Repo::connect(format!("sqlite://{}", db_path)).await } -pub async fn create_paths_for_repo(root: &PathBuf, settings: &Settings) -> RepoResult<()> { +pub async fn create_paths_for_repo( + root: &PathBuf, + settings: &Settings, + storage_path: &str, + thumbnail_path: &str, +) -> RepoResult<()> { if !root.exists() { fs::create_dir_all(&root).await?; } @@ -22,11 +27,11 @@ pub async fn create_paths_for_repo(root: &PathBuf, settings: &Settings) -> RepoR if !db_path.exists() { fs::create_dir_all(db_path.parent().unwrap()).await?; } - let storage_path = root.join(&settings.default_file_store); + let storage_path = root.join(storage_path); if !storage_path.exists() { fs::create_dir_all(storage_path).await?; } - let thumbnail_path = root.join(&settings.thumbnail_store); + let thumbnail_path = root.join(thumbnail_path); if !thumbnail_path.exists() { fs::create_dir_all(thumbnail_path).await?; }