lazy_static cleanup
general code cleanup in filecache
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
@@ -16,13 +14,6 @@ use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
|
||||
|
||||
type CacheGuard<T> = Arc<RwLock<T>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileEntryError {
|
||||
NeedsUpdate,
|
||||
EmptyFile,
|
||||
FileOpenError,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileEntry {
|
||||
path: CacheGuard<std::path::PathBuf>,
|
||||
@@ -57,7 +48,6 @@ impl FileEntry {
|
||||
Arc::new(RwLock::new(String::from(&*path)))
|
||||
}
|
||||
|
||||
// HACK: this whole function has been hacked up trying to fix dead locks.
|
||||
fn do_hash(&mut self) {
|
||||
let path_ptr = self.path.clone();
|
||||
let path_lock = path_ptr.read().unwrap();
|
||||
@@ -75,7 +65,6 @@ impl FileEntry {
|
||||
};
|
||||
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
// HACK: this feels bad...
|
||||
hasher.update_rayon(
|
||||
&temp_content
|
||||
.bytes()
|
||||
@@ -98,36 +87,6 @@ impl FileEntry {
|
||||
|
||||
*self.hash.write().unwrap() = Some(hasher.finalize());
|
||||
}
|
||||
/*
|
||||
|
||||
loop {
|
||||
let has_content = ptr.read().unwrap().is_some();
|
||||
if has_content {
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher.update_rayon(content.get_ref());
|
||||
|
||||
|
||||
let hash_ptr = self.hash.clone();
|
||||
let hash_ptr = hash_ptr.write().unwrap();
|
||||
let hash_ptr = Some(hasher.finalize());
|
||||
|
||||
break;
|
||||
} else {
|
||||
|
||||
let content_lock = self.content.clone();
|
||||
let mut content = content_lock.write().unwrap();
|
||||
|
||||
if content.is_none() {
|
||||
let path_lock = self.path.clone();
|
||||
let file = std::fs::File::open(path_lock.read().unwrap().as_path());
|
||||
let file = file.unwrap_or_else(|_| panic!("issue opening file for {:#?}", &self.path));
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +101,7 @@ pub struct FileCache {
|
||||
cache: CacheGuard<HashMap<String, CacheGuard<FileEntry>>>,
|
||||
cache_dir: std::path::PathBuf,
|
||||
notify_watcher: RecommendedWatcher,
|
||||
notify_thread: std::thread::JoinHandle<()>,
|
||||
_notify_thread: std::thread::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl FileCache {
|
||||
@@ -171,7 +130,7 @@ impl FileCache {
|
||||
cache: Arc::new(RwLock::new(HashMap::new())),
|
||||
cache_dir: cache_dir.to_path_buf(),
|
||||
notify_watcher: notify::Watcher::new(tx, Duration::from_secs(1)).unwrap(),
|
||||
notify_thread: thread::Builder::new()
|
||||
_notify_thread: thread::Builder::new()
|
||||
.name("notify-thread".to_string())
|
||||
.spawn(move || FileCache::notify_loop(rx))
|
||||
.unwrap(),
|
||||
@@ -222,10 +181,9 @@ impl FileCache {
|
||||
}
|
||||
|
||||
fn notify_loop(rx: Receiver<DebouncedEvent>) {
|
||||
let this_thread = std::thread::current();
|
||||
log::info!("notify loop starting on thread-{:?}", &this_thread);
|
||||
log::info!("notify loop starting on thread-{:?}", std::thread::current());
|
||||
|
||||
let thread_name: String = match &this_thread.name() {
|
||||
let thread_name: String = match std::thread::current().name() {
|
||||
Some(s) => s.to_string(),
|
||||
None => "notify-thread".to_string(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user