fix: get_meta_path if no extension
This commit is contained in:
parent
93ce266c90
commit
0595b93dca
@ -57,11 +57,8 @@ impl HttpSourceAssetReader {
|
|||||||
|
|
||||||
/// See [`crate::io::get_meta_path`]
|
/// See [`crate::io::get_meta_path`]
|
||||||
fn make_meta_uri(&self, path: &Path) -> PathBuf {
|
fn make_meta_uri(&self, path: &Path) -> PathBuf {
|
||||||
let mut uri = self.make_uri(path);
|
let meta_path = crate::io::get_meta_path(path);
|
||||||
let mut extension = path.extension().unwrap_or_default().to_os_string();
|
self.make_uri(&meta_path)
|
||||||
extension.push(".meta");
|
|
||||||
uri.set_extension(extension);
|
|
||||||
uri
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
pub(crate) fn get_meta_path(path: &Path) -> PathBuf {
|
||||||
let mut meta_path = path.to_path_buf();
|
let mut meta_path = path.to_path_buf();
|
||||||
let mut extension = path.extension().unwrap_or_default().to_os_string();
|
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.set_extension(extension);
|
||||||
meta_path
|
meta_path
|
||||||
}
|
}
|
||||||
@ -784,3 +789,24 @@ impl Stream for EmptyPathStream {
|
|||||||
Poll::Ready(None)
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user