| 90 | } |
| 91 | |
| 92 | fn query(&self) -> String { |
| 93 | // Make a list of files separated with commas. |
| 94 | // Each is a dictionary with a "name" key |
| 95 | let file_list = { |
| 96 | let mut s = String::new(); |
| 97 | let mut it = self.files.keys().peekable(); |
| 98 | while let Some(name) = it.next() { |
| 99 | s.reserve(name.len() + 13); |
| 100 | s.push_str("{\"name\":\""); |
| 101 | s.push_str(name); |
| 102 | s.push_str("\"}"); |
| 103 | if it.peek().is_some() { |
| 104 | s.push_str(", "); |
| 105 | } |
| 106 | } |
| 107 | s |
| 108 | }; |
| 109 | |
| 110 | // Make a list of directories |
| 111 | let subdir_list = { |
| 112 | let mut s = String::new(); |
| 113 | let mut it = self.subdirs.keys().peekable(); |
| 114 | while let Some(name) = it.next() { |
| 115 | s.reserve(name.len() + 13); |
| 116 | s.push_str("{\"name\":\""); |
| 117 | s.push_str(name); |
| 118 | s.push_str("\"}"); |
| 119 | if it.peek().is_some() { |
| 120 | s.push_str(", "); |
| 121 | } |
| 122 | } |
| 123 | s |
| 124 | }; |
| 125 | |
| 126 | // Combine into a String and return |
| 127 | format!("{{ |
| 128 | \"short\": \"Ramdisk directory\", |
| 129 | \"messages\": [{{\"name\": \"open\", |
| 130 | \"tag\": {open_tag}}}, |
| 131 | {{\"name\": \"query\", |
| 132 | \"tag\": {query_tag}}}], |
| 133 | \"subdirs\": [{subdir_list}], |
| 134 | \"files\": [{file_list}]}}", |
| 135 | open_tag = message::OPEN, |
| 136 | query_tag = message::QUERY, |
| 137 | file_list = file_list, |
| 138 | subdir_list = subdir_list) |
| 139 | } |
| 140 | |
| 141 | /// Make a sub-directory |
| 142 | fn make_dir(&mut self, path: &str) -> Result<Arc<RwLock<dyn DirLike + Send + Sync>>, syscalls::SyscallError> { |