use crate::directory::entry_container::Directory;
use crate::execution_scope::ExecutionScope;
use crate::path::Path;
use fidl::endpoints::{create_endpoints, ServerEnd};
use fidl_fuchsia_io as fio;
use std::sync::Arc;
#[macro_use]
pub mod test_utils;
pub mod common;
pub mod immutable;
pub mod mutable;
mod connection;
pub mod dirents_sink;
pub mod entry;
pub mod entry_container;
pub mod helper;
pub mod read_dirents;
pub mod simple;
pub mod traversal_position;
pub mod watchers;
#[derive(Clone)]
pub struct DirectoryOptions {
pub(crate) rights: fio::Operations,
}
impl DirectoryOptions {
pub(crate) fn to_io1(&self) -> fio::OpenFlags {
let mut flags = fio::OpenFlags::empty();
if self.rights.contains(fio::R_STAR_DIR) {
flags |= fio::OpenFlags::RIGHT_READABLE;
}
if self.rights.contains(fio::W_STAR_DIR) {
flags |= fio::OpenFlags::RIGHT_WRITABLE;
}
if self.rights.contains(fio::X_STAR_DIR) {
flags |= fio::OpenFlags::RIGHT_EXECUTABLE;
}
flags
}
pub fn new(rights: fio::Operations) -> DirectoryOptions {
Self { rights: rights }
}
}
impl Default for DirectoryOptions {
fn default() -> Self {
DirectoryOptions { rights: fio::R_STAR_DIR }
}
}
pub fn spawn_directory<D: Directory + ?Sized>(dir: Arc<D>) -> fio::DirectoryProxy {
spawn_directory_with_options(dir, DirectoryOptions::default())
}
pub fn spawn_directory_with_options<D: Directory + ?Sized>(
dir: Arc<D>,
options: DirectoryOptions,
) -> fio::DirectoryProxy {
let (client_end, server_end) = create_endpoints::<fio::DirectoryMarker>();
let scope = ExecutionScope::new();
let rights = options.to_io1();
dir.open(scope, rights, Path::dot(), ServerEnd::new(server_end.into_channel()));
client_end.into_proxy()
}