put upend into its own subdir, fix self-scanning

feat/vaults
Tomáš Mládek 2021-12-05 12:43:43 +01:00
parent 10eaab6e2d
commit b5a013e973
2 changed files with 17 additions and 8 deletions

View File

@ -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<P: AsRef<Path>>(
@ -247,16 +248,23 @@ pub fn open_upend<P: AsRef<Path>>(
) -> Result<OpenResult> {
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::<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()
.connection_customizer(Box::new(ConnectionOptions {
enable_foreign_keys: true,

View File

@ -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<UpdatePathOutcome>;
#[derive(Debug, Clone)]
enum UpdatePathOutcome {
Added(PathBuf),
Unchanged(PathBuf),
@ -105,17 +106,17 @@ fn _rescan_vault<T: AsRef<Path>>(
// Walk through the vault, find all paths
debug!("Traversing vault directory");
let absolute_dir_path = fs::canonicalize(&directory)?;
let path_entries: Vec<PathBuf> = 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<T: AsRef<Path>>(
&rw_pool,
&resolve_cache,
path,
&absolute_path,
&absolute_dir_path,
&existing_files,
)?;