make internal bin the second entry in bundles#1024
Conversation
|
😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details. |
aa07767 to
7356854
Compare
073e460 to
53eec9a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1024 +/- ##
==========================================
+ Coverage 81.33% 81.66% +0.33%
==========================================
Files 69 69
Lines 14526 14527 +1
==========================================
+ Hits 11815 11864 +49
+ Misses 2711 2663 -48 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7356854 to
363806c
Compare
53eec9a to
b8c16c1
Compare
363806c to
57f1b88
Compare
b8c16c1 to
31f21f9
Compare
57f1b88 to
bb29ba9
Compare
31f21f9 to
d6c56a5
Compare
| pub fn internal_bundled_file(&self) -> Option<BundledFile> { | ||
| pub fn internal_bundled_file(&self) -> Option<&BundledFile> { | ||
| match self { | ||
| Self::V0_7_8(data) => data.internal_bundled_file.clone(), | ||
| Self::V0_7_7(data) => data.internal_bundled_file.clone(), | ||
| Self::V0_7_8(data) => data.internal_bundled_file.as_ref(), | ||
| Self::V0_7_7(data) => data.internal_bundled_file.as_ref(), |
There was a problem hiding this comment.
Not sure why this was cloned before, but from what I can see only a reference is needed
| // Add the internal binary file if it exists. | ||
| if let Some(bundled_file) = self.meta.internal_bundled_file.as_ref() { | ||
| let path = std::path::Path::new(&bundled_file.original_path); | ||
| let mut file = File::open(path)?; | ||
| tar.append_file(&bundled_file.path, &mut file)?; | ||
| total_bytes_in += std::fs::metadata(path)?.len(); | ||
| } |
| /// Reads and decompresses a .tar.zstd file from an input stream into just a `meta.json` file. | ||
| /// This assumes that the `meta.json` file will be the first entry in the tarball. | ||
| pub async fn parse_meta_from_tarball<R: AsyncBufRead>(input: R) -> anyhow::Result<VersionedBundle> { |
There was a problem hiding this comment.
moved down to be closer to the other parse_ functions
| /// Reads and decompresses a .tar.zstd file from an input stream into just the internal bin file. | ||
| pub async fn parse_internal_bin_from_tarball<R: AsyncBufRead>( |
There was a problem hiding this comment.
also moved down to be closer to other parse_ functions
| Err(anyhow::anyhow!("No internal.bin file found in the tarball")) | ||
| } | ||
|
|
||
| #[cfg(test)] |
There was a problem hiding this comment.
tests were getting a bit noisy, so I tried to clean them up a bit and make them clearer
|
|
||
| #[tokio::test] | ||
| pub async fn test_nondefault_internal_bin_path() { | ||
| pub async fn test_internal_bin_is_second_entry() { |
There was a problem hiding this comment.
added this test new to check that the generated bundle's second entry is the internal bin
| #[test] | ||
| pub fn test_no_duplicate_internal_file() { | ||
| #[tokio::test] | ||
| pub async fn test_internal_bin_is_backwards_compatible_with_last_entry() { |
There was a problem hiding this comment.
also added this test to ensure that parsing the internal bin works even if it's not the second entry
| async fn parse_meta_entry<R: AsyncBufRead>( | ||
| entry: &mut Entry<Archive<ZstdDecoder<Pin<Box<R>>>>>, | ||
| ) -> anyhow::Result<Option<VersionedBundle>> { | ||
| if let Some(path_str) = entry.path()?.to_str() | ||
| && path_str == META_FILENAME | ||
| { | ||
| let mut meta_bytes = Vec::new(); | ||
| entry.read_to_end(&mut meta_bytes).await?; | ||
| Ok(Some(parse_meta(meta_bytes)?)) | ||
| } else { | ||
| Ok(None) | ||
| } | ||
| } | ||
|
|
||
| anyhow::Result::Err(anyhow::anyhow!( | ||
| "No {} file found in the tarball", | ||
| target_name | ||
| )) | ||
| async fn parse_meta_from_first_entry<R: AsyncBufRead>( |
There was a problem hiding this comment.
which should be used? parse_meta_from_first_entry?
There was a problem hiding this comment.
Neither parse_meta_entry nor parse_meta_from_first_entry are public, they are only used internally here. Additionally, they take different arguments:
parse_meta_entry: takes a&mut Entry<T>(object containing file bytes)parse_meta_from_first_entry: takes a&mut Entries<T>(stream of files)
parse_meta_entry is for parsing the entry itself while parse_meta_from_first_entry is for ensuring the first entry of the stream parses
d6c56a5 to
ec667b2
Compare
depends on:
This greatly improves our ability to extract only what's needed from byte streams