DB path is now a constructor parameter of Index struct

This commit is contained in:
Antoine Gersant 2016-12-02 17:41:29 -08:00
parent 791c9bc104
commit 15505f8991
2 changed files with 13 additions and 5 deletions

View file

@ -12,6 +12,7 @@ use utils;
use vfs::VfsConfig;
const DEFAULT_CONFIG_FILE_NAME: &'static str = "polaris.toml";
const INDEX_FILE_NAME: &'static str = "index.sqlite";
const CONFIG_SECRET: &'static str = "auth_secret";
const CONFIG_MOUNT_DIRS: &'static str = "mount_dirs";
const CONFIG_MOUNT_DIR_NAME: &'static str = "name";
@ -29,6 +30,7 @@ const CONFIG_DDNS_PASSWORD: &'static str = "password";
#[derive(Debug)]
pub enum ConfigError {
IoError(io::Error),
CacheDirectoryError,
ConfigDirectoryError,
TOMLParseError,
RegexError(regex::Error),
@ -98,6 +100,13 @@ impl Config {
try!(config.parse_album_art_pattern(&parsed_config));
try!(config.parse_ddns(&parsed_config));
let mut index_path = match utils::get_cache_root() {
Err(_) => return Err(ConfigError::CacheDirectoryError),
Ok(p) => p,
};
index_path.push(INDEX_FILE_NAME);
config.index.path = index_path;
Ok(config)
}

View file

@ -3,23 +3,22 @@ use regex::Regex;
use sqlite;
use sqlite::{Connection, State, Statement, Value};
use std::fs;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread;
use std::time;
use error::*;
use metadata;
use utils;
use vfs::Vfs;
const INDEX_FILE_NAME: &'static str = "index.sqlite";
const INDEX_BUILDING_INSERT_BUFFER_SIZE: usize = 250; // Insertions in each transaction
const INDEX_LOCK_TIMEOUT: usize = 1000; // In milliseconds
pub struct IndexConfig {
pub album_art_pattern: Option<Regex>,
pub sleep_duration: u64, // in seconds
pub path: PathBuf,
}
impl IndexConfig {
@ -27,6 +26,7 @@ impl IndexConfig {
IndexConfig {
sleep_duration: 60 * 30, // 30 minutes
album_art_pattern: None,
path: Path::new(":memory:").to_path_buf(),
}
}
}
@ -186,8 +186,7 @@ impl<'db> Drop for IndexBuilder<'db> {
impl Index {
pub fn new(vfs: Arc<Vfs>, config: &IndexConfig) -> Result<Index, PError> {
let mut path = try!(utils::get_cache_root());
path.push(INDEX_FILE_NAME);
let path = &config.path;
println!("Reading or creating index from {}", path.to_string_lossy());