Handle messages for a given directory # Arguments `directory` - The directory being viewed or modified `comm_handle` - Waits for messages on this CommHandle `readwrite` - If true, allow modifications `handler` - A closure that will be called with any unhandled message
(
directory: Arc<RwLock<dyn DirLike + Sync + Send>>,
comm_handle: CommHandle,
readwrite: bool,
mut handler: F)
| 315 | /// * `handler` - A closure that will be called with any unhandled message |
| 316 | /// |
| 317 | pub fn handle_directory<F>( |
| 318 | directory: Arc<RwLock<dyn DirLike + Sync + Send>>, |
| 319 | comm_handle: CommHandle, |
| 320 | readwrite: bool, |
| 321 | mut handler: F) |
| 322 | where |
| 323 | F: FnMut(syscalls::Message) -> (), |
| 324 | { |
| 325 | dispatch_loop( |
| 326 | &comm_handle, |
| 327 | |msg| { |
| 328 | match msg { |
| 329 | Message::Long( |
| 330 | message::DELETE, |
| 331 | MessageData::Value(length), |
| 332 | MessageData::MemoryHandle(handle)) => { |
| 333 | // Delete a file |
| 334 | |
| 335 | if !readwrite { |
| 336 | // Error! Read-only |
| 337 | if let Err((err, _msg)) = syscalls::send(&comm_handle, |
| 338 | syscalls::Message::Short( |
| 339 | message::ERROR_DENIED, 0, 0)) { |
| 340 | // Failed to send reply |
| 341 | println!("[std:handle_directory] Reply failed: {}", err); |
| 342 | } |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | // Get the path string |
| 347 | let u8_slice = handle.as_slice::<u8>(length as usize); |
| 348 | if let Err((err, _msg)) = if let Ok(path) = str::from_utf8(u8_slice) { |
| 349 | match directory.write().remove_file(path) { |
| 350 | Ok(_) => syscalls::send(&comm_handle, |
| 351 | syscalls::Message::Short( |
| 352 | message::OK, 0, 0)), |
| 353 | Err(sys_err) => |
| 354 | syscalls::send(&comm_handle, |
| 355 | syscalls::Message::Short( |
| 356 | message::ERROR, sys_err.as_u64(), 0)) |
| 357 | } |
| 358 | } else { |
| 359 | // UTF-8 error |
| 360 | syscalls::send(&comm_handle, |
| 361 | syscalls::Message::Short( |
| 362 | message::ERROR_INVALID_UTF8, 0, 0)) |
| 363 | } { |
| 364 | // Failed to send reply |
| 365 | println!("[std:handle_directory] Reply failed: {}", err); |
| 366 | } |
| 367 | } |
| 368 | Message::Long( |
| 369 | message::MKDIR, |
| 370 | MessageData::Value(length), |
| 371 | MessageData::MemoryHandle(handle)) => { |
| 372 | // Make a directory |
| 373 | |
| 374 | if !readwrite { |