diff options
author | Aleksey Kladov <[email protected]> | 2018-09-16 10:54:24 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-16 11:07:39 +0100 |
commit | b5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch) | |
tree | 9dca564f8e51b298dced01c4ce669c756dce3142 /crates/server/src/vfs.rs | |
parent | ba0bfeee12e19da40b5eabc8d0408639af10e96f (diff) |
rename all things
Diffstat (limited to 'crates/server/src/vfs.rs')
-rw-r--r-- | crates/server/src/vfs.rs | 71 |
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 @@ | |||
1 | use std::{ | ||
2 | path::{PathBuf, Path}, | ||
3 | fs, | ||
4 | }; | ||
5 | |||
6 | use walkdir::WalkDir; | ||
7 | |||
8 | use { | ||
9 | thread_watcher::{Worker, ThreadWatcher}, | ||
10 | }; | ||
11 | |||
12 | |||
13 | #[derive(Debug)] | ||
14 | pub struct FileEvent { | ||
15 | pub path: PathBuf, | ||
16 | pub kind: FileEventKind, | ||
17 | } | ||
18 | |||
19 | #[derive(Debug)] | ||
20 | pub enum FileEventKind { | ||
21 | Add(String), | ||
22 | } | ||
23 | |||
24 | pub 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 | |||
41 | fn 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 | } | ||