DB path is now a constructor parameter of Index struct
This commit is contained in:
parent
791c9bc104
commit
15505f8991
2 changed files with 13 additions and 5 deletions
|
@ -12,6 +12,7 @@ use utils;
|
||||||
use vfs::VfsConfig;
|
use vfs::VfsConfig;
|
||||||
|
|
||||||
const DEFAULT_CONFIG_FILE_NAME: &'static str = "polaris.toml";
|
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_SECRET: &'static str = "auth_secret";
|
||||||
const CONFIG_MOUNT_DIRS: &'static str = "mount_dirs";
|
const CONFIG_MOUNT_DIRS: &'static str = "mount_dirs";
|
||||||
const CONFIG_MOUNT_DIR_NAME: &'static str = "name";
|
const CONFIG_MOUNT_DIR_NAME: &'static str = "name";
|
||||||
|
@ -29,6 +30,7 @@ const CONFIG_DDNS_PASSWORD: &'static str = "password";
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
IoError(io::Error),
|
IoError(io::Error),
|
||||||
|
CacheDirectoryError,
|
||||||
ConfigDirectoryError,
|
ConfigDirectoryError,
|
||||||
TOMLParseError,
|
TOMLParseError,
|
||||||
RegexError(regex::Error),
|
RegexError(regex::Error),
|
||||||
|
@ -98,6 +100,13 @@ impl Config {
|
||||||
try!(config.parse_album_art_pattern(&parsed_config));
|
try!(config.parse_album_art_pattern(&parsed_config));
|
||||||
try!(config.parse_ddns(&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)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,23 +3,22 @@ use regex::Regex;
|
||||||
use sqlite;
|
use sqlite;
|
||||||
use sqlite::{Connection, State, Statement, Value};
|
use sqlite::{Connection, State, Statement, Value};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
use error::*;
|
use error::*;
|
||||||
use metadata;
|
use metadata;
|
||||||
use utils;
|
|
||||||
use vfs::Vfs;
|
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_BUILDING_INSERT_BUFFER_SIZE: usize = 250; // Insertions in each transaction
|
||||||
const INDEX_LOCK_TIMEOUT: usize = 1000; // In milliseconds
|
const INDEX_LOCK_TIMEOUT: usize = 1000; // In milliseconds
|
||||||
|
|
||||||
pub struct IndexConfig {
|
pub struct IndexConfig {
|
||||||
pub album_art_pattern: Option<Regex>,
|
pub album_art_pattern: Option<Regex>,
|
||||||
pub sleep_duration: u64, // in seconds
|
pub sleep_duration: u64, // in seconds
|
||||||
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexConfig {
|
impl IndexConfig {
|
||||||
|
@ -27,6 +26,7 @@ impl IndexConfig {
|
||||||
IndexConfig {
|
IndexConfig {
|
||||||
sleep_duration: 60 * 30, // 30 minutes
|
sleep_duration: 60 * 30, // 30 minutes
|
||||||
album_art_pattern: None,
|
album_art_pattern: None,
|
||||||
|
path: Path::new(":memory:").to_path_buf(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,8 +186,7 @@ impl<'db> Drop for IndexBuilder<'db> {
|
||||||
impl Index {
|
impl Index {
|
||||||
pub fn new(vfs: Arc<Vfs>, config: &IndexConfig) -> Result<Index, PError> {
|
pub fn new(vfs: Arc<Vfs>, config: &IndexConfig) -> Result<Index, PError> {
|
||||||
|
|
||||||
let mut path = try!(utils::get_cache_root());
|
let path = &config.path;
|
||||||
path.push(INDEX_FILE_NAME);
|
|
||||||
|
|
||||||
println!("Reading or creating index from {}", path.to_string_lossy());
|
println!("Reading or creating index from {}", path.to_string_lossy());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue