From 0595b93dcafc961880d42d53051effde7ea1cbf1 Mon Sep 17 00:00:00 2001 From: Peter Hayman Date: Fri, 4 Jul 2025 14:02:16 +1000 Subject: [PATCH] fix: get_meta_path if no extension --- crates/bevy_asset/src/http_source.rs | 7 ++----- crates/bevy_asset/src/io/mod.rs | 30 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/bevy_asset/src/http_source.rs b/crates/bevy_asset/src/http_source.rs index cae49f7bb0..6d42ad7dfa 100644 --- a/crates/bevy_asset/src/http_source.rs +++ b/crates/bevy_asset/src/http_source.rs @@ -57,11 +57,8 @@ impl HttpSourceAssetReader { /// See [`crate::io::get_meta_path`] fn make_meta_uri(&self, path: &Path) -> PathBuf { - let mut uri = self.make_uri(path); - let mut extension = path.extension().unwrap_or_default().to_os_string(); - extension.push(".meta"); - uri.set_extension(extension); - uri + let meta_path = crate::io::get_meta_path(path); + self.make_uri(&meta_path) } } diff --git a/crates/bevy_asset/src/io/mod.rs b/crates/bevy_asset/src/io/mod.rs index fce77ebf1f..9fd1c5b2dd 100644 --- a/crates/bevy_asset/src/io/mod.rs +++ b/crates/bevy_asset/src/io/mod.rs @@ -763,11 +763,16 @@ impl Reader for SliceReader<'_> { } } -/// Appends `.meta` to the given path. +/// Appends `.meta` to the given path: +/// - `foo` becomes `foo.meta` +/// - `foo.bar` becomes `foo.bar.meta` pub(crate) fn get_meta_path(path: &Path) -> PathBuf { let mut meta_path = path.to_path_buf(); let mut extension = path.extension().unwrap_or_default().to_os_string(); - extension.push(".meta"); + if !extension.is_empty() { + extension.push("."); + } + extension.push("meta"); meta_path.set_extension(extension); meta_path } @@ -784,3 +789,24 @@ impl Stream for EmptyPathStream { Poll::Ready(None) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn get_meta_path_no_extension() { + assert_eq!( + get_meta_path(Path::new("foo")).to_str().unwrap(), + "foo.meta" + ); + } + + #[test] + fn get_meta_path_with_extension() { + assert_eq!( + get_meta_path(Path::new("foo.bar")).to_str().unwrap(), + "foo.bar.meta" + ); + } +}