better error handling
This commit is contained in:
parent
b0f7e72c49
commit
abd8ccefa4
1 changed files with 16 additions and 4 deletions
|
@ -86,7 +86,7 @@ pub struct Vfs {
|
||||||
pending_changes: Vec<VfsChange>,
|
pending_changes: Vec<VfsChange>,
|
||||||
worker: io::Worker,
|
worker: io::Worker,
|
||||||
worker_handle: WorkerHandle,
|
worker_handle: WorkerHandle,
|
||||||
watcher: Watcher,
|
watcher: Option<Watcher>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Vfs {
|
impl fmt::Debug for Vfs {
|
||||||
|
@ -99,7 +99,13 @@ impl Vfs {
|
||||||
pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) {
|
pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) {
|
||||||
let (worker, worker_handle) = io::start();
|
let (worker, worker_handle) = io::start();
|
||||||
|
|
||||||
let watcher = Watcher::start(worker.inp.clone()).unwrap(); // TODO return Result?
|
let watcher = match Watcher::start(worker.inp.clone()) {
|
||||||
|
Ok(watcher) => Some(watcher),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("could not start watcher: {}", e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut res = Vfs {
|
let mut res = Vfs {
|
||||||
roots: Arena::default(),
|
roots: Arena::default(),
|
||||||
|
@ -134,7 +140,11 @@ impl Vfs {
|
||||||
filter: Box::new(filter),
|
filter: Box::new(filter),
|
||||||
};
|
};
|
||||||
res.worker.inp.send(task).unwrap();
|
res.worker.inp.send(task).unwrap();
|
||||||
res.watcher.watch(path).unwrap();
|
if let Some(ref mut watcher) = res.watcher {
|
||||||
|
if let Err(e) = watcher.watch(path) {
|
||||||
|
log::warn!("could not watch \"{}\": {}", path.display(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let roots = res.roots.iter().map(|(id, _)| id).collect();
|
let roots = res.roots.iter().map(|(id, _)| id).collect();
|
||||||
(res, roots)
|
(res, roots)
|
||||||
|
@ -350,7 +360,9 @@ impl Vfs {
|
||||||
|
|
||||||
/// Sutdown the VFS and terminate the background watching thread.
|
/// Sutdown the VFS and terminate the background watching thread.
|
||||||
pub fn shutdown(self) -> thread::Result<()> {
|
pub fn shutdown(self) -> thread::Result<()> {
|
||||||
let _ = self.watcher.shutdown();
|
if let Some(watcher) = self.watcher {
|
||||||
|
let _ = watcher.shutdown();
|
||||||
|
}
|
||||||
let _ = self.worker.shutdown();
|
let _ = self.worker.shutdown();
|
||||||
self.worker_handle.shutdown()
|
self.worker_handle.shutdown()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue