async fn load_relative_url<'a>(
        mut parsed_url: Url,
        component_decls_guard: MutexGuard<'a, HashMap<Url, ResolveableComponent>>,
    ) -> Result<fsys::Component, fsys::ResolverError> {
        let component_url = parsed_url.as_str().to_string();
        let fragment = match parsed_url.fragment() {
            Some(fragment) => fragment.to_string(),
            None => return Err(fsys::ResolverError::ManifestNotFound),
        };

        parsed_url.set_fragment(None);
        let package_dir = component_decls_guard
            .get(&parsed_url)
            .ok_or(fsys::ResolverError::ManifestNotFound)?
            .package_dir
            .clone();
        let package_dir = package_dir.ok_or(fsys::ResolverError::PackageNotFound)?;
        let manifest_file =
            io_util::open_file(&package_dir, Path::new(&fragment), fio::OPEN_RIGHT_READABLE)
                .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        let component_decl: fsys::ComponentDecl = io_util::read_file_fidl(&manifest_file)
            .await
            .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        cm_fidl_validator::validate(&component_decl)
            .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        let (client_end, server_end) = create_endpoints::<fio::DirectoryMarker>()
            .map_err(|_| fsys::ResolverError::Internal)?;
        package_dir
            .clone(fio::CLONE_FLAG_SAME_RIGHTS, ServerEnd::new(server_end.into_channel()))
            .map_err(|_| fsys::ResolverError::Io)?;
        Ok(fsys::Component {
            resolved_url: Some(component_url.clone()),
            decl: Some(encode(component_decl).map_err(|_| fsys::ResolverError::Internal)?),
            package: Some(fsys::Package {
                package_url: Some(component_url),
                package_dir: Some(client_end),
                ..fsys::Package::EMPTY
            }),
            ..fsys::Component::EMPTY
        })
    }
// Realm builder never generates URLs with fragments. If we're asked to resolve a URL with
// one, then this must be from component manager attempting to make sense of a relative URL
// where the parent of the component is an absolute realm builder URL. We rewrite relative
// URLs to be absolute realm builder URLs at build time, but if a component is added at
// runtime (as in, to a collection) then realm builder doesn't have a chance to do this
// rewrite.
//
// To handle this: let's use the fragment to look for a component in the test package.
Realm builder never generates URLs with fragments. If we're asked to resolve a URL with
one, then this must be from component manager attempting to make sense of a relative URL
where the parent of the component is an absolute realm builder URL. We rewrite relative
URLs to be absolute realm builder URLs at build time, but if a component is added at
runtime (as in, to a collection) then realm builder doesn't have a chance to do this
rewrite.

To handle this: let's use the fragment to look for a component in the test package.
Realm builder never generates URLs with fragments . If we ' re asked to resolve a URL with one then this must be from component manager attempting to make sense of a relative URL where the parent of the component is an absolute realm builder URL . We rewrite relative URLs to be absolute realm builder URLs at build time but if a component is added at runtime ( as in to a collection ) then realm builder doesn ' t have a chance to do this rewrite . To handle this : let ' s use the fragment to look for a component in the test package .
async fn load_relative_url<'a>(
        mut parsed_url: Url,
        component_decls_guard: MutexGuard<'a, HashMap<Url, ResolveableComponent>>,
    ) -> Result<fsys::Component, fsys::ResolverError> {
        let component_url = parsed_url.as_str().to_string();
        let fragment = match parsed_url.fragment() {
            Some(fragment) => fragment.to_string(),
            None => return Err(fsys::ResolverError::ManifestNotFound),
        };
        parsed_url.set_fragment(None);
        let package_dir = component_decls_guard
            .get(&parsed_url)
            .ok_or(fsys::ResolverError::ManifestNotFound)?
            .package_dir
            .clone();
        let package_dir = package_dir.ok_or(fsys::ResolverError::PackageNotFound)?;
        let manifest_file =
            io_util::open_file(&package_dir, Path::new(&fragment), fio::OPEN_RIGHT_READABLE)
                .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        let component_decl: fsys::ComponentDecl = io_util::read_file_fidl(&manifest_file)
            .await
            .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        cm_fidl_validator::validate(&component_decl)
            .map_err(|_| fsys::ResolverError::ManifestNotFound)?;
        let (client_end, server_end) = create_endpoints::<fio::DirectoryMarker>()
            .map_err(|_| fsys::ResolverError::Internal)?;
        package_dir
            .clone(fio::CLONE_FLAG_SAME_RIGHTS, ServerEnd::new(server_end.into_channel()))
            .map_err(|_| fsys::ResolverError::Io)?;
        Ok(fsys::Component {
            resolved_url: Some(component_url.clone()),
            decl: Some(encode(component_decl).map_err(|_| fsys::ResolverError::Internal)?),
            package: Some(fsys::Package {
                package_url: Some(component_url),
                package_dir: Some(client_end),
                ..fsys::Package::EMPTY
            }),
            ..fsys::Component::EMPTY
        })
    }
async fn load_relative_url < ' a > ( mut parsed_url : Url , component_decls_guard : MutexGuard < ' a , HashMap < Url , ResolveableComponent > > , ) -> Result < fsys :: Component , fsys :: ResolverError > { let component_url = parsed_url . as_str ( ) . to_string ( ) ; let fragment = match parsed_url . fragment ( ) { Some ( fragment ) => fragment . to_string ( ) , None => return Err ( fsys :: ResolverError :: ManifestNotFound ) , } ; parsed_url . set_fragment ( None ) ; let package_dir = component_decls_guard . get ( & parsed_url ) . ok_or ( fsys :: ResolverError :: ManifestNotFound ) ? . package_dir . clone ( ) ; let package_dir = package_dir . ok_or ( fsys :: ResolverError :: PackageNotFound ) ? ; let manifest_file = io_util :: open_file ( & package_dir , Path :: new ( & fragment ) , fio :: OPEN_RIGHT_READABLE ) . map_err ( | _ | fsys :: ResolverError :: ManifestNotFound ) ? ; let component_decl : fsys :: ComponentDecl = io_util :: read_file_fidl ( & manifest_file ) . await . map_err ( | _ | fsys :: ResolverError :: ManifestNotFound ) ? ; cm_fidl_validator :: validate ( & component_decl ) . map_err ( | _ | fsys :: ResolverError :: ManifestNotFound ) ? ; let ( client_end , server_end ) = create_endpoints :: < fio :: DirectoryMarker > ( ) . map_err ( | _ | fsys :: ResolverError :: Internal ) ? ; package_dir . clone ( fio :: CLONE_FLAG_SAME_RIGHTS , ServerEnd :: new ( server_end . into_channel ( ) ) ) . map_err ( | _ | fsys :: ResolverError :: Io ) ? ; Ok ( fsys :: Component { resolved_url : Some ( component_url . clone ( ) ) , decl : Some ( encode ( component_decl ) . map_err ( | _ | fsys :: ResolverError :: Internal ) ? ) , package : Some ( fsys :: Package { package_url : Some ( component_url ) , package_dir : Some ( client_end ) , .. fsys :: Package :: EMPTY } ) , .. fsys :: Component :: EMPTY } ) }
Realm builder never generates URLs with fragments.
Realm builder never generates URLs with fragments .
parsed_url
Url
component_decls_guard
MutexGuard<'a, HashMap<Url, ResolveableComponent>>
parsed_url
Url
component_decls_guard
MutexGuard<'a, HashMap<Url, ResolveableComponent>>