diff --git a/src/database/mod.rs b/src/database/mod.rs index d8c357c..63533dd 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -238,6 +238,7 @@ pub struct OpenResult { pub new: bool, } +pub const UPEND_SUBDIR: &str = ".upend"; pub const DATABASE_FILENAME: &str = "upend.sqlite3"; pub fn open_upend>( @@ -247,16 +248,23 @@ pub fn open_upend>( ) -> Result { 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 { 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."); - let manager = ConnectionManager::::new(database_path.to_str().unwrap()); + let manager = ConnectionManager::::new( + upend_path.join(DATABASE_FILENAME).to_str().unwrap(), + ); let pool = r2d2::Pool::builder() .connection_customizer(Box::new(ConnectionOptions { enable_foreign_keys: true, diff --git a/src/filesystem.rs b/src/filesystem.rs index 0dc2479..74fc776 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,7 +12,7 @@ use crate::database::entry::{Entry, EntryValue, InvariantEntry}; use crate::database::hierarchies::{resolve_path_cached, ResolveCache, UNode, UPath}; use crate::database::inner::models; 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::jobs::{Job, JobContainer, JobId, State}; @@ -80,6 +80,7 @@ pub async fn rescan_vault( type UpdatePathResult = Result; +#[derive(Debug, Clone)] enum UpdatePathOutcome { Added(PathBuf), Unchanged(PathBuf), @@ -105,17 +106,17 @@ fn _rescan_vault>( // Walk through the vault, find all paths debug!("Traversing vault directory"); + let absolute_dir_path = fs::canonicalize(&directory)?; let path_entries: Vec = WalkDir::new(&directory) .follow_links(true) .into_iter() .filter_map(|e| e.ok()) - .filter(|e| e.path().is_file() && e.file_name() != DATABASE_FILENAME) .map(|e| fs::canonicalize(e.into_path()).unwrap()) + .filter(|e| !e.starts_with(&absolute_dir_path.join(UPEND_SUBDIR))) .collect(); // Prepare for processing 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()?)?)); // Actual processing @@ -129,7 +130,7 @@ fn _rescan_vault>( &rw_pool, &resolve_cache, path, - &absolute_path, + &absolute_dir_path, &existing_files, )?;