Switched load_package_tree's over to using the filesystem annotations

This commit is contained in:
Michael-F-Bryan
2023-06-06 21:55:15 +08:00
parent 584baaf9fd
commit be897c8d49
5 changed files with 221 additions and 33 deletions

View File

@ -188,7 +188,7 @@ pub struct PackageInfo {
impl PackageInfo {
pub fn from_manifest(manifest: &Manifest) -> Result<Self, Error> {
let WapmAnnotations { name, version, .. } = manifest
.package_annotation("wapm")?
.wapm()?
.context("Unable to find the \"wapm\" annotations")?;
let dependencies = manifest
@ -210,7 +210,7 @@ impl PackageInfo {
})
.collect();
let filesystem = filesystem_mapping_from_manifest(manifest);
let filesystem = filesystem_mapping_from_manifest(manifest)?;
Ok(PackageInfo {
name,
@ -230,15 +230,40 @@ impl PackageInfo {
}
}
fn filesystem_mapping_from_manifest(_manifest: &Manifest) -> Vec<FileSystemMapping> {
// FIXME(Michael-F-Bryan): wapm2pirita never added filesystem mappings to the manifest
// That means we need to
// - Figure out whether filesystem mappings belong to the whole package or
// if each command has their own set of mappings
// - Update wapm-targz-to-pirita to copy the [fs] table across
// - Re-generate all packages on WAPM
// - Update this function to copy metadata into our internal datastructures
Vec::new()
fn filesystem_mapping_from_manifest(
manifest: &Manifest,
) -> Result<Vec<FileSystemMapping>, serde_cbor::Error> {
match manifest.filesystem()? {
Some(webc::metadata::annotations::FileSystemMappings(mappings)) => {
let mappings = mappings
.into_iter()
.map(|mapping| FileSystemMapping {
volume_name: mapping.volume_name,
mount_path: mapping.mount_path,
dependency_name: mapping.from,
})
.collect();
Ok(mappings)
}
None => {
// A "fs" annotation hasn't been attached to this package. This was
// the case when *.webc files were generated by wapm2pirita version
// 1.0.29 and earlier.
//
// To maintain compatibility with those older packages, we'll say
// that the "atom" volume from the current package is mounted to "/"
// and contains all files in the package.
tracing::debug!(
"No \"fs\" package annotations found. Mounting the \"atom\" volume to \"/\" for compatibility."
);
Ok(vec![FileSystemMapping {
volume_name: "atom".to_string(),
mount_path: "/".to_string(),
dependency_name: None,
}])
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]