/// Resolve the package.
///
/// FIXME: at the moment, we are proxying to Amber to resolve a package name and variant to a
/// merkleroot. Because of this, we cant' implement the update policy, so we just ignore it.
Resolve the package.
FIXME: at the moment, we are proxying to Amber to resolve a package name and variant to a
merkleroot. Because of this, we cant' implement the update policy, so we just ignore it.
Resolve the package . FIXME : at the moment we are proxying to Amber to resolve a package name and variant to a merkleroot . Because of this we cant ' implement the update policy so we just ignore it .
async fn resolve<'a>(
    rewrites: &'a Arc<RwLock<RewriteManager>>,
    amber: &'a AmberProxy,
    cache: &'a PackageCacheProxy,
    pkg_uri: String,
    selectors: Vec<String>,
    _update_policy: UpdatePolicy,
    dir_request: ServerEnd<DirectoryMarker>,
) -> Result<(), Status> {
    let uri = PkgUri::parse(&pkg_uri).map_err(|err| {
        fx_log_err!("failed to parse package uri {:?}: {}", pkg_uri, err);
        Err(Status::INVALID_ARGS)
    })?;
    let was_fuchsia_host = uri.host() == "fuchsia.com";
    let uri = rewrites.read().rewrite(uri);
    // FIXME: at the moment only the fuchsia.com host is supported.
    if !was_fuchsia_host && uri.host() != "fuchsia.com" {
        fx_log_err!("package uri's host is currently unsupported: {}", uri);
        return Err(Status::INVALID_ARGS);
    }
    // While the fuchsia-pkg:// spec doesn't require a package name, we do.
    let name = uri.name().ok_or_else(|| {
        fx_log_err!("package uri is missing a package name: {}", uri);
        Err(Status::INVALID_ARGS)
    })?;
    // While the fuchsia-pkg:// spec allows resource paths, the package resolver should not be
    // given one.
    if uri.resource().is_some() {
        fx_log_err!("package uri should not contain a resource name: {}", uri);
        return Err(Status::INVALID_ARGS);
    }
    // FIXME: need to implement selectors.
    if !selectors.is_empty() {
        fx_log_warn!("resolve does not support selectors yet");
    }
    // FIXME: use the package cache to fetch the package instead of amber.
    // Ask amber to cache the package.
    let chan = await!(amber.get_update_complete(&name, uri.variant(), uri.package_hash()))
        .map_err(|err| {
            fx_log_err!("error communicating with amber: {:?}", err);
            Status::INTERNAL
        })?;
    let merkle = await!(wait_for_update_to_complete(chan, &uri)).map_err(|err| {
        fx_log_err!("error when waiting for amber to complete: {:?}", err);
        err
    })?;
    fx_log_info!(
        "resolved {} as {} with the selectors {:?} to {}",
        pkg_uri,
        uri,
        selectors,
        merkle
    );
    await!(cache.open(&mut merkle.into(), &mut selectors.iter().map(|s| s.as_str()), dir_request))
        .map_err(|err| {
            fx_log_err!("error opening {}: {:?}", merkle, err);
            Status::INTERNAL
        })?;
    Ok(())
}
async fn resolve < ' a > ( rewrites : & ' a Arc < RwLock < RewriteManager > > , amber : & ' a AmberProxy , cache : & ' a PackageCacheProxy , pkg_uri : String , selectors : Vec < String > , _update_policy : UpdatePolicy , dir_request : ServerEnd < DirectoryMarker > , ) -> Result < ( ) , Status > { let uri = PkgUri :: parse ( & pkg_uri ) . map_err ( | err | { fx_log_err ! ( " " pkg_uri err ) ; Err ( Status :: INVALID_ARGS ) } ) ? ; let was_fuchsia_host = uri . host ( ) == " " ; let uri = rewrites . read ( ) . rewrite ( uri ) ; // FIXME: at the moment only the fuchsia.com host is supported. if ! was_fuchsia_host && uri . host ( ) != " " { fx_log_err ! ( " " uri ) ; return Err ( Status :: INVALID_ARGS ) ; } // While the fuchsia-pkg:// spec doesn't require a package name, we do. let name = uri . name ( ) . ok_or_else ( | | { fx_log_err ! ( " " uri ) ; Err ( Status :: INVALID_ARGS ) } ) ? ; // While the fuchsia-pkg:// spec allows resource paths, the package resolver should not be // given one. if uri . resource ( ) . is_some ( ) { fx_log_err ! ( " " uri ) ; return Err ( Status :: INVALID_ARGS ) ; } // FIXME: need to implement selectors. if ! selectors . is_empty ( ) { fx_log_warn ! ( " " ) ; } // FIXME: use the package cache to fetch the package instead of amber. // Ask amber to cache the package. let chan = await ! ( amber get_update_complete ( name uri variant ( ) uri package_hash ( ) ) ) . map_err ( | err | { fx_log_err ! ( " " err ) ; Status :: INTERNAL } ) ? ; let merkle = await ! ( wait_for_update_to_complete ( chan uri ) ) . map_err ( | err | { fx_log_err ! ( " " err ) ; err } ) ? ; fx_log_info ! ( " " pkg_uri uri selectors merkle ) ; await ! ( cache open ( mut merkle into ( ) mut selectors iter ( ) map ( s s as_str ( ) ) dir_request ) ) . map_err ( | err | { fx_log_err ! ( " " merkle err ) ; Status :: INTERNAL } ) ? ; Ok ( ( ) ) }
Resolve the package.
Resolve the package .
rewrites
&'a Arc<RwLock<RewriteManager>>
amber
&'a AmberProxy
cache
&'a PackageCacheProxy
pkg_uri
String
selectors
Vec<String>
_update_policy
UpdatePolicy
dir_request
ServerEnd<DirectoryMarker>