Run Manifest parsing in block_in_place mode

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-23 19:55:09 +10:00
parent 60caa9ee17
commit e18ac6e117
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
4 changed files with 25 additions and 27 deletions

View file

@ -71,6 +71,5 @@ pub async fn fetch_crate_cratesio(
TarBasedFmt::Tgz,
ManifestVisitor::new(manifest_dir_path),
)
.await?
.load_manifest()
.await
}

View file

@ -29,23 +29,11 @@ impl ManifestVisitor {
vfs: Vfs::new(),
}
}
/// Load binstall metadata using the extracted information stored in memory.
pub(super) fn load_manifest(&self) -> Result<Manifest<Meta>, BinstallError> {
debug!("Loading manifest directly from extracted file");
// Load and parse manifest
let mut manifest = Manifest::<Meta>::from_slice_with_metadata(&self.cargo_toml_content)?;
// Checks vfs for binary output names
manifest.complete_from_abstract_filesystem(&self.vfs)?;
// Return metadata
Ok(manifest)
}
}
impl TarEntriesVisitor for ManifestVisitor {
type Target = Manifest<Meta>;
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError> {
for res in entries {
let mut entry = res?;
@ -78,4 +66,18 @@ impl TarEntriesVisitor for ManifestVisitor {
Ok(())
}
/// Load binstall metadata using the extracted information stored in memory.
fn finish(self) -> Result<Self::Target, BinstallError> {
debug!("Loading manifest directly from extracted file");
// Load and parse manifest
let mut manifest = Manifest::from_slice_with_metadata(&self.cargo_toml_content)?;
// Checks vfs for binary output names
manifest.complete_from_abstract_filesystem(&self.vfs)?;
// Return metadata
Ok(manifest)
}
}

View file

@ -130,16 +130,16 @@ pub async fn download_tar_based_and_visit<V: TarEntriesVisitor + Debug + Send +
url: Url,
fmt: TarBasedFmt,
visitor: V,
) -> Result<V, BinstallError> {
) -> Result<V::Target, BinstallError> {
let stream = create_request(url).await?;
debug!("Downloading and extracting then in-memory processing");
let visitor = extract_tar_based_stream_and_visit(stream, fmt, visitor).await?;
let ret = extract_tar_based_stream_and_visit(stream, fmt, visitor).await?;
debug!("Download, extraction and in-memory procession OK");
Ok(visitor)
Ok(ret)
}
/// Fetch install path from environment

View file

@ -99,20 +99,17 @@ where
/// Visitor must iterate over all entries.
/// Entires can be in arbitary order.
pub trait TarEntriesVisitor {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError>;
}
type Target;
impl<V: TarEntriesVisitor> TarEntriesVisitor for &mut V {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError> {
(*self).visit(entries)
}
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError>;
fn finish(self) -> Result<Self::Target, BinstallError>;
}
pub async fn extract_tar_based_stream_and_visit<S, V, E>(
stream: S,
fmt: TarBasedFmt,
mut visitor: V,
) -> Result<V, BinstallError>
) -> Result<V::Target, BinstallError>
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
V: TarEntriesVisitor + Debug + Send + 'static,
@ -124,6 +121,6 @@ where
let mut tar = create_tar_decoder(reader, fmt)?;
visitor.visit(tar.entries()?)?;
Ok(visitor)
visitor.finish()
})
}