pub async fn load_cache_packages(
    index: &mut DynamicIndex,
    cache_packages: &CachePackages,
    blobfs: &blobfs::Client,
) {
    // This function is called before anything writes to or deletes from blobfs, so if it needs
    // to be sped up, it might be possible to:
    //   1. get the list of all available blobs with `blobfs.list_known_blobs()`
    //   2. for each cache package, check the list for the meta.far and the necessary content
    //      blobs (obtained with `RootDir::external_file_hashes()`)
    // This alternate approach requires that blobfs responds to `fuchsia.io/Directory.ReadDirents`
    // with *only* blobs that are readable, i.e. blobs for which the `USER_0` signal is set (which
    // is currently checked per-package per-blob by `blobfs.filter_to_missing_blobs()`). Would need
    // to confirm with the storage team that blobfs meets this requirement.
    // TODO(fxb/90656): ensure non-fuchsia.com URLs are correctly handled in dynamic index.
    for url in cache_packages.contents() {
        let hash = url.package_hash();
        let path = PackagePath::from_name_and_variant(
            url.name().clone(),
            url.variant().unwrap_or(&fuchsia_pkg::PackageVariant::zero()).clone(),
        );
        let required_blobs = match super::enumerate_package_blobs(blobfs, &hash).await {
            Ok(Some((path_from_far, required_blobs))) => {
                if path_from_far != path {
                    fx_log_err!(
                        "load_cache_packages: path mismatch for {} from manifest {} from far {}",
                        hash,
                        path,
                        path_from_far
                    );
                    continue;
                }
                required_blobs
            }
            Ok(None) => continue,
            Err(e) => {
                fx_log_err!(
                    "load_cache_packages: enumerate_package_blobs of {} {} failed: {:#}",
                    hash,
                    path,
                    anyhow!(e)
                );
                continue;
            }
        };
        if !blobfs.filter_to_missing_blobs(&required_blobs).await.is_empty() {
            continue;
        }
        let () = index.start_install(hash);
        if let Err(e) = index.fulfill_meta_far(hash, path, required_blobs) {
            fx_log_err!(
                "load_cache_packages: fulfill_meta_far of {} failed: {:#}",
                hash,
                anyhow!(e)
            );
            let () = index.cancel_install(&hash);
            continue;
        }
        if let Err(e) = index.complete_install(hash) {
            fx_log_err!(
                "load_cache_packages: complete_install of {} failed: {:#}",
                hash,
                anyhow!(e)
            );
            let () = index.cancel_install(&hash);
            continue;
        }
    }
}
/// For any package referenced by the cache packages manifest that has all of its blobs present in
/// blobfs, imports those packages into the provided dynamic index.
For any package referenced by the cache packages manifest that has all of its blobs present in
blobfs, imports those packages into the provided dynamic index.
For any package referenced by the cache packages manifest that has all of its blobs present in blobfs imports those packages into the provided dynamic index .
pub async fn load_cache_packages(
    index: &mut DynamicIndex,
    cache_packages: &CachePackages,
    blobfs: &blobfs::Client,
) {
    // This function is called before anything writes to or deletes from blobfs, so if it needs
    // to be sped up, it might be possible to:
    //   1. get the list of all available blobs with `blobfs.list_known_blobs()`
    //   2. for each cache package, check the list for the meta.far and the necessary content
    //      blobs (obtained with `RootDir::external_file_hashes()`)
    // This alternate approach requires that blobfs responds to `fuchsia.io/Directory.ReadDirents`
    // with *only* blobs that are readable, i.e. blobs for which the `USER_0` signal is set (which
    // is currently checked per-package per-blob by `blobfs.filter_to_missing_blobs()`). Would need
    // to confirm with the storage team that blobfs meets this requirement.
    // TODO(fxb/90656): ensure non-fuchsia.com URLs are correctly handled in dynamic index.
    for url in cache_packages.contents() {
        let hash = url.package_hash();
        let path = PackagePath::from_name_and_variant(
            url.name().clone(),
            url.variant().unwrap_or(&fuchsia_pkg::PackageVariant::zero()).clone(),
        );
        let required_blobs = match super::enumerate_package_blobs(blobfs, &hash).await {
            Ok(Some((path_from_far, required_blobs))) => {
                if path_from_far != path {
                    fx_log_err!(
                        "load_cache_packages: path mismatch for {} from manifest {} from far {}",
                        hash,
                        path,
                        path_from_far
                    );
                    continue;
                }
                required_blobs
            }
            Ok(None) => continue,
            Err(e) => {
                fx_log_err!(
                    "load_cache_packages: enumerate_package_blobs of {} {} failed: {:#}",
                    hash,
                    path,
                    anyhow!(e)
                );
                continue;
            }
        };
        if !blobfs.filter_to_missing_blobs(&required_blobs).await.is_empty() {
            continue;
        }
        let () = index.start_install(hash);
        if let Err(e) = index.fulfill_meta_far(hash, path, required_blobs) {
            fx_log_err!(
                "load_cache_packages: fulfill_meta_far of {} failed: {:#}",
                hash,
                anyhow!(e)
            );
            let () = index.cancel_install(&hash);
            continue;
        }
        if let Err(e) = index.complete_install(hash) {
            fx_log_err!(
                "load_cache_packages: complete_install of {} failed: {:#}",
                hash,
                anyhow!(e)
            );
            let () = index.cancel_install(&hash);
            continue;
        }
    }
}
pub async fn load_cache_packages ( index : & mut DynamicIndex , cache_packages : & CachePackages , blobfs : & blobfs :: Client , ) { // This function is called before anything writes to or deletes from blobfs, so if it needs // to be sped up, it might be possible to: //   1. get the list of all available blobs with `blobfs.list_known_blobs()` //   2. for each cache package, check the list for the meta.far and the necessary content //      blobs (obtained with `RootDir::external_file_hashes()`) // This alternate approach requires that blobfs responds to `fuchsia.io/Directory.ReadDirents` // with *only* blobs that are readable, i.e. blobs for which the `USER_0` signal is set (which // is currently checked per-package per-blob by `blobfs.filter_to_missing_blobs()`). Would need // to confirm with the storage team that blobfs meets this requirement. // TODO(fxb/90656): ensure non-fuchsia.com URLs are correctly handled in dynamic index. for url in cache_packages . contents ( ) { let hash = url . package_hash ( ) ; let path = PackagePath :: from_name_and_variant ( url . name ( ) . clone ( ) , url . variant ( ) . unwrap_or ( & fuchsia_pkg :: PackageVariant :: zero ( ) ) . clone ( ) , ) ; let required_blobs = match super :: enumerate_package_blobs ( blobfs , & hash ) . await { Ok ( Some ( ( path_from_far , required_blobs ) ) ) => { if path_from_far != path { fx_log_err ! ( " " hash path path_from_far ) ; continue ; } required_blobs } Ok ( None ) => continue , Err ( e ) => { fx_log_err ! ( " " hash path anyhow ( e ) ) ; continue ; } } ; if ! blobfs . filter_to_missing_blobs ( & required_blobs ) . await . is_empty ( ) { continue ; } let ( ) = index . start_install ( hash ) ; if let Err ( e ) = index . fulfill_meta_far ( hash , path , required_blobs ) { fx_log_err ! ( " " hash anyhow ( e ) ) ; let ( ) = index . cancel_install ( & hash ) ; continue ; } if let Err ( e ) = index . complete_install ( hash ) { fx_log_err ! ( " " hash anyhow ( e ) ) ; let ( ) = index . cancel_install ( & hash ) ; continue ; } } }
For any package referenced by the cache packages manifest that has all of its blobs present in
blobfs, imports those packages into the provided dynamic index.
For any package referenced by the cache packages manifest that has all of its blobs present in blobfs imports those packages into the provided dynamic index .
index
&mut DynamicIndex
cache_packages
&CachePackages
blobfs
&blobfs::Client
index
&mut DynamicIndex
cache_packages
&CachePackages
blobfs
&blobfs::Client