put upend into its own subdir, fix self-scanning
parent
10eaab6e2d
commit
b5a013e973
|
@ -238,6 +238,7 @@ pub struct OpenResult {
|
||||||
pub new: bool,
|
pub new: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const UPEND_SUBDIR: &str = ".upend";
|
||||||
pub const DATABASE_FILENAME: &str = "upend.sqlite3";
|
pub const DATABASE_FILENAME: &str = "upend.sqlite3";
|
||||||
|
|
||||||
pub fn open_upend<P: AsRef<Path>>(
|
pub fn open_upend<P: AsRef<Path>>(
|
||||||
|
@ -247,16 +248,23 @@ pub fn open_upend<P: AsRef<Path>>(
|
||||||
) -> Result<OpenResult> {
|
) -> Result<OpenResult> {
|
||||||
embed_migrations!("./migrations/upend/");
|
embed_migrations!("./migrations/upend/");
|
||||||
|
|
||||||
let database_path = db_path.unwrap_or_else(|| dirpath.as_ref().join(DATABASE_FILENAME));
|
let upend_path = db_path.unwrap_or_else(|| dirpath.as_ref().join(UPEND_SUBDIR));
|
||||||
|
|
||||||
if reinitialize {
|
if reinitialize {
|
||||||
trace!("Reinitializing - removing previous database...");
|
trace!("Reinitializing - removing previous database...");
|
||||||
let _ = fs::remove_file(&database_path);
|
let _ = fs::remove_dir_all(&upend_path);
|
||||||
|
}
|
||||||
|
let new = !upend_path.exists();
|
||||||
|
|
||||||
|
if new {
|
||||||
|
trace!("Creating UpEnd subdirectory...");
|
||||||
|
fs::create_dir(&upend_path)?;
|
||||||
}
|
}
|
||||||
let new = !database_path.exists();
|
|
||||||
|
|
||||||
trace!("Creating pool.");
|
trace!("Creating pool.");
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(database_path.to_str().unwrap());
|
let manager = ConnectionManager::<SqliteConnection>::new(
|
||||||
|
upend_path.join(DATABASE_FILENAME).to_str().unwrap(),
|
||||||
|
);
|
||||||
let pool = r2d2::Pool::builder()
|
let pool = r2d2::Pool::builder()
|
||||||
.connection_customizer(Box::new(ConnectionOptions {
|
.connection_customizer(Box::new(ConnectionOptions {
|
||||||
enable_foreign_keys: true,
|
enable_foreign_keys: true,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::database::entry::{Entry, EntryValue, InvariantEntry};
|
||||||
use crate::database::hierarchies::{resolve_path_cached, ResolveCache, UNode, UPath};
|
use crate::database::hierarchies::{resolve_path_cached, ResolveCache, UNode, UPath};
|
||||||
use crate::database::inner::models;
|
use crate::database::inner::models;
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
file_set_valid, insert_entry, insert_file, retrieve_all_files, DbPool, DATABASE_FILENAME,
|
file_set_valid, insert_entry, insert_file, retrieve_all_files, DbPool, UPEND_SUBDIR,
|
||||||
};
|
};
|
||||||
use crate::util::hash::{Hash, Hashable};
|
use crate::util::hash::{Hash, Hashable};
|
||||||
use crate::util::jobs::{Job, JobContainer, JobId, State};
|
use crate::util::jobs::{Job, JobContainer, JobId, State};
|
||||||
|
@ -80,6 +80,7 @@ pub async fn rescan_vault(
|
||||||
|
|
||||||
type UpdatePathResult = Result<UpdatePathOutcome>;
|
type UpdatePathResult = Result<UpdatePathOutcome>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
enum UpdatePathOutcome {
|
enum UpdatePathOutcome {
|
||||||
Added(PathBuf),
|
Added(PathBuf),
|
||||||
Unchanged(PathBuf),
|
Unchanged(PathBuf),
|
||||||
|
@ -105,17 +106,17 @@ fn _rescan_vault<T: AsRef<Path>>(
|
||||||
|
|
||||||
// Walk through the vault, find all paths
|
// Walk through the vault, find all paths
|
||||||
debug!("Traversing vault directory");
|
debug!("Traversing vault directory");
|
||||||
|
let absolute_dir_path = fs::canonicalize(&directory)?;
|
||||||
let path_entries: Vec<PathBuf> = WalkDir::new(&directory)
|
let path_entries: Vec<PathBuf> = WalkDir::new(&directory)
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.filter(|e| e.path().is_file() && e.file_name() != DATABASE_FILENAME)
|
|
||||||
.map(|e| fs::canonicalize(e.into_path()).unwrap())
|
.map(|e| fs::canonicalize(e.into_path()).unwrap())
|
||||||
|
.filter(|e| !e.starts_with(&absolute_dir_path.join(UPEND_SUBDIR)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Prepare for processing
|
// Prepare for processing
|
||||||
let rw_pool = Arc::new(RwLock::new(pool.clone()));
|
let rw_pool = Arc::new(RwLock::new(pool.clone()));
|
||||||
let absolute_path = fs::canonicalize(&directory)?;
|
|
||||||
let existing_files = Arc::new(RwLock::new(retrieve_all_files(&pool.get()?)?));
|
let existing_files = Arc::new(RwLock::new(retrieve_all_files(&pool.get()?)?));
|
||||||
|
|
||||||
// Actual processing
|
// Actual processing
|
||||||
|
@ -129,7 +130,7 @@ fn _rescan_vault<T: AsRef<Path>>(
|
||||||
&rw_pool,
|
&rw_pool,
|
||||||
&resolve_cache,
|
&resolve_cache,
|
||||||
path,
|
path,
|
||||||
&absolute_path,
|
&absolute_dir_path,
|
||||||
&existing_files,
|
&existing_files,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue