Fix assets with odd extensions and fix race condition with duplicate assets with different sources (#4436)

This commit is contained in:
Evan Almloff authored and GitHub committed 2025-07-18 11:08:18 -07:00
1 parent 9478525dd0
commit 71b00ab171
6 files changed
+19 -10

No files matched your search

+2 -1
View File
@@ -97,7 +97,8 @@ pub(crate) fn process_file_to_with_options(
}
// If everything was successful, rename the temp file to the final output path
std::fs::rename(temp_path, output_path).context("Failed to rename output file")?;
std::fs::rename(temp_path, output_path)
.with_context(|| format!("Failed to rename output file to: {}", output_path.display()))?;
Ok(())
}
+4 -1
View File
@@ -152,7 +152,10 @@ pub fn add_hash_to_asset(asset: &mut BundledAsset) {
};
if let Some(ext) = ext {
bundled_path.set_extension(ext);
// Push the extension to the bundled path. There may be multiple extensions (e.g. .js.map)
// with one left after the file_stem is extracted above so we need to push the extension
// instead of setting it
bundled_path.as_mut_os_string().push(format!(".{ext}"));
}
let bundled_path = bundled_path.to_string_lossy().to_string();
+8 -3
View File
@@ -79,9 +79,14 @@ impl AssetManifest {
.is_some_and(|assets| assets.contains(asset))
}
/// Iterate over all the assets in the manifest
pub fn assets(&self) -> impl Iterator<Item = &BundledAsset> {
self.assets.values().flat_map(|assets| assets.iter())
/// Iterate over all the assets with unique output paths in the manifest. This will not include
/// assets that have different source paths, but the same file contents.
pub fn unique_assets(&self) -> impl Iterator<Item = &BundledAsset> {
let mut seen = HashSet::new();
self.assets
.values()
.flat_map(|assets| assets.iter())
.filter(move |asset| seen.insert(asset.bundled_path()))
}
pub fn load_from_file(path: &Path) -> anyhow::Result<Self> {