From 3ff4ae460b0f1ace16f59e262a680d7b970bef4b Mon Sep 17 00:00:00 2001 From: Jason LeBrun Date: Thu, 7 Nov 2024 16:39:29 +0000 Subject: [PATCH] Better path handling in oak_file_utils Bug: b/377874528 Change-Id: I5930006fd16f8ee1d3dc505f348b028116174438 --- oak_file_utils/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/oak_file_utils/src/lib.rs b/oak_file_utils/src/lib.rs index 5100afef61..127dc5ce9e 100644 --- a/oak_file_utils/src/lib.rs +++ b/oak_file_utils/src/lib.rs @@ -50,12 +50,13 @@ impl CompatRlocation for Option { #[cfg(feature = "bazel")] pub fn data_path(path: impl AsRef) -> PathBuf { const DATA_PATH_PREFIX: &str = "oak"; + let mut pb: PathBuf = DATA_PATH_PREFIX.into(); + pb.push(path); + let r = runfiles::Runfiles::create().expect("Couldn't initialize runfiles"); - let p = runfiles::rlocation!(r, format!("{DATA_PATH_PREFIX}/{}", path.as_ref().display())) - .compat_wrap() - .expect("Couldn't get runfile path"); + let p = runfiles::rlocation!(r, &pb).compat_wrap().expect("Couldn't get runfile path"); if !p.exists() { - panic!("Data dependency not found: {}", path.as_ref().display()); + panic!("Data dependency not found: {}", pb.display()); } p }