pub async fn find_exposed_root_directory_capability(
    model: &Model,
    path: CapabilityPath,
) -> Result<(CapabilityPath, AbsoluteMoniker), ModelError> {
    let expose_dir_decl = {
        let root_moniker = AbsoluteMoniker::new(vec![]);
        let root_realm = model.look_up_realm(&root_moniker).await?;
        let realm_state = root_realm.lock_state().await;
        let root_decl = realm_state
            .as_ref()
            .expect("find_exposed_root_directory_capability: not resolved")
            .decl();
        root_decl
            .exposes
            .iter()
            .find_map(|e| match e {
                ExposeDecl::Directory(dir_decl) if dir_decl.target_path == path => Some(dir_decl),
                _ => None,
            })
            .ok_or(ModelError::capability_discovery_error(format_err!(
                "root component does not expose directory {:?}",
                path
            )))?
            .clone()
    };
    match &expose_dir_decl.source {
        cm_rust::ExposeSource::Framework => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "root realm cannot expose framework directories"
            )))
        }
        cm_rust::ExposeSource::Self_ => {
            return Ok((expose_dir_decl.source_path.clone(), AbsoluteMoniker::root()))
        }
        cm_rust::ExposeSource::Child(_) => {
            let mut wp = WalkPosition {
                capability: ComponentCapability::Expose(ExposeDecl::Directory(
                    expose_dir_decl.clone(),
                )),
                last_child_moniker: None,
                moniker: Some(vec![].into()),
            };
            let capability_source = walk_expose_chain(model, &mut wp).await?;
            match capability_source {
                CapabilitySource::Component {
                    capability:
                        ComponentCapability::Expose(ExposeDecl::Directory(ExposeDirectoryDecl {
                            source_path,
                            ..
                        })),
                    source_moniker,
                } => return Ok((source_path, source_moniker)),
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "unexpected capability source"
                    )))
                }
            }
        }
    }
}
/// Finds the providing realm and path of a directory exposed by the root realm to component
/// manager.
Finds the providing realm and path of a directory exposed by the root realm to component
manager.
Finds the providing realm and path of a directory exposed by the root realm to component manager .
pub async fn find_exposed_root_directory_capability(
    model: &Model,
    path: CapabilityPath,
) -> Result<(CapabilityPath, AbsoluteMoniker), ModelError> {
    let expose_dir_decl = {
        let root_moniker = AbsoluteMoniker::new(vec![]);
        let root_realm = model.look_up_realm(&root_moniker).await?;
        let realm_state = root_realm.lock_state().await;
        let root_decl = realm_state
            .as_ref()
            .expect("find_exposed_root_directory_capability: not resolved")
            .decl();
        root_decl
            .exposes
            .iter()
            .find_map(|e| match e {
                ExposeDecl::Directory(dir_decl) if dir_decl.target_path == path => Some(dir_decl),
                _ => None,
            })
            .ok_or(ModelError::capability_discovery_error(format_err!(
                "root component does not expose directory {:?}",
                path
            )))?
            .clone()
    };
    match &expose_dir_decl.source {
        cm_rust::ExposeSource::Framework => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "root realm cannot expose framework directories"
            )))
        }
        cm_rust::ExposeSource::Self_ => {
            return Ok((expose_dir_decl.source_path.clone(), AbsoluteMoniker::root()))
        }
        cm_rust::ExposeSource::Child(_) => {
            let mut wp = WalkPosition {
                capability: ComponentCapability::Expose(ExposeDecl::Directory(
                    expose_dir_decl.clone(),
                )),
                last_child_moniker: None,
                moniker: Some(vec![].into()),
            };
            let capability_source = walk_expose_chain(model, &mut wp).await?;
            match capability_source {
                CapabilitySource::Component {
                    capability:
                        ComponentCapability::Expose(ExposeDecl::Directory(ExposeDirectoryDecl {
                            source_path,
                            ..
                        })),
                    source_moniker,
                } => return Ok((source_path, source_moniker)),
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "unexpected capability source"
                    )))
                }
            }
        }
    }
}
pub async fn find_exposed_root_directory_capability ( model : & Model , path : CapabilityPath , ) -> Result < ( CapabilityPath , AbsoluteMoniker ) , ModelError > { let expose_dir_decl = { let root_moniker = AbsoluteMoniker :: new ( vec ! [ ] ) ; let root_realm = model . look_up_realm ( & root_moniker ) . await ? ; let realm_state = root_realm . lock_state ( ) . await ; let root_decl = realm_state . as_ref ( ) . expect ( " " ) . decl ( ) ; root_decl . exposes . iter ( ) . find_map ( | e | match e { ExposeDecl :: Directory ( dir_decl ) if dir_decl . target_path == path => Some ( dir_decl ) , _ => None , } ) . ok_or ( ModelError :: capability_discovery_error ( format_err ! ( " " path ) ) ) ? . clone ( ) } ; match & expose_dir_decl . source { cm_rust :: ExposeSource :: Framework => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } cm_rust :: ExposeSource :: Self_ => { return Ok ( ( expose_dir_decl . source_path . clone ( ) , AbsoluteMoniker :: root ( ) ) ) } cm_rust :: ExposeSource :: Child ( _ ) => { let mut wp = WalkPosition { capability : ComponentCapability :: Expose ( ExposeDecl :: Directory ( expose_dir_decl . clone ( ) , ) ) , last_child_moniker : None , moniker : Some ( vec ! [ ] . into ( ) ) , } ; let capability_source = walk_expose_chain ( model , & mut wp ) . await ? ; match capability_source { CapabilitySource :: Component { capability : ComponentCapability :: Expose ( ExposeDecl :: Directory ( ExposeDirectoryDecl { source_path , .. } ) ) , source_moniker , } => return Ok ( ( source_path , source_moniker ) ) , _ => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } } } } }
Finds the providing realm and path of a directory exposed by the root realm to component
manager.
Finds the providing realm and path of a directory exposed by the root realm to component manager .
model
&Model
path
CapabilityPath