diff --git a/Cargo.lock b/Cargo.lock index e5c320456326..667af64d7f26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4641,6 +4641,7 @@ dependencies = [ "arrow2", "backtrace", "bytemuck", + "clean-path", "criterion", "crossbeam", "document-features", diff --git a/crates/re_log_types/Cargo.toml b/crates/re_log_types/Cargo.toml index 79cce06fda9c..89b3157be2d7 100644 --- a/crates/re_log_types/Cargo.toml +++ b/crates/re_log_types/Cargo.toml @@ -50,6 +50,7 @@ arrow2 = { workspace = true, features = [ ] } backtrace.workspace = true bytemuck.workspace = true +clean-path.workspace = true document-features.workspace = true fixed = { workspace = true, default-features = false, features = ["serde"] } # `fixed` depends on `half`, so even though `half` is not directly used in this crate, diff --git a/crates/re_log_types/src/path/entity_path.rs b/crates/re_log_types/src/path/entity_path.rs index 069b2441a154..d1f00d5856be 100644 --- a/crates/re_log_types/src/path/entity_path.rs +++ b/crates/re_log_types/src/path/entity_path.rs @@ -118,11 +118,27 @@ impl EntityPath { /// /// The file path separators will NOT become splits in the new path. /// The returned path will only have one part. - #[cfg(not(target_arch = "wasm32"))] pub fn from_file_path_as_single_string(file_path: &std::path::Path) -> Self { Self::from_single_string(file_path.to_string_lossy().to_string()) } + /// Treat the file path as an entity path hierarchy. + /// + /// The file path separators will become splits in the new path. + pub fn from_file_path(file_path: &std::path::Path) -> Self { + use clean_path::Clean as _; + Self::new( + file_path + .clean() + .iter() + // NOTE: This can only happen when hitting the leading `/` in an absolute path, and + // we currently don't support entity paths with leading `/`s. + .filter(|p| p != &std::ffi::OsStr::new("/")) + .map(|p| EntityPathPart::from(p.to_string_lossy().to_string())) + .collect(), + ) + } + /// Treat the string as one opaque string, NOT splitting on any slashes. /// /// The given string is expected to be unescaped, i.e. any `\` is treated as a normal character.