aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/vfs.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-16 10:54:24 +0100
committerAleksey Kladov <[email protected]>2018-09-16 11:07:39 +0100
commitb5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch)
tree9dca564f8e51b298dced01c4ce669c756dce3142 /crates/server/src/vfs.rs
parentba0bfeee12e19da40b5eabc8d0408639af10e96f (diff)
rename all things
Diffstat (limited to 'crates/server/src/vfs.rs')
-rw-r--r--crates/server/src/vfs.rs71
1 files changed, 0 insertions, 71 deletions
diff --git a/crates/server/src/vfs.rs b/crates/server/src/vfs.rs
deleted file mode 100644
index a1c1783f2..000000000
--- a/crates/server/src/vfs.rs
+++ /dev/null
@@ -1,71 +0,0 @@
1use std::{
2 path::{PathBuf, Path},
3 fs,
4};
5
6use walkdir::WalkDir;
7
8use {
9 thread_watcher::{Worker, ThreadWatcher},
10};
11
12
13#[derive(Debug)]
14pub struct FileEvent {
15 pub path: PathBuf,
16 pub kind: FileEventKind,
17}
18
19#[derive(Debug)]
20pub enum FileEventKind {
21 Add(String),
22}
23
24pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatcher) {
25 Worker::<PathBuf, (PathBuf, Vec<FileEvent>)>::spawn(
26 "roots loader",
27 128, |input_receiver, output_sender| {
28 input_receiver
29 .into_iter()
30 .map(|path| {
31 debug!("loading {} ...", path.as_path().display());
32 let events = load_root(path.as_path());
33 debug!("... loaded {}", path.as_path().display());
34 (path, events)
35 })
36 .for_each(|it| output_sender.send(it))
37 }
38 )
39}
40
41fn load_root(path: &Path) -> Vec<FileEvent> {
42 let mut res = Vec::new();
43 for entry in WalkDir::new(path) {
44 let entry = match entry {
45 Ok(entry) => entry,
46 Err(e) => {
47 warn!("watcher error: {}", e);
48 continue;
49 }
50 };
51 if !entry.file_type().is_file() {
52 continue;
53 }
54 let path = entry.path();
55 if path.extension().and_then(|os| os.to_str()) != Some("rs") {
56 continue;
57 }
58 let text = match fs::read_to_string(path) {
59 Ok(text) => text,
60 Err(e) => {
61 warn!("watcher error: {}", e);
62 continue;
63 }
64 };
65 res.push(FileEvent {
66 path: path.to_owned(),
67 kind: FileEventKind::Add(text),
68 })
69 }
70 res
71}