Fix issue with default paths on init

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent ab16ba4873
commit bac13f4853

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

@ -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<i64> = resolved_tags.into_iter().map(|t| t.id()).collect();

@ -14,7 +14,12 @@ pub async fn get_repo(db_path: &str) -> RepoResult<Repo> {
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?;
}

Loading…
Cancel
Save