From 996beab7081f96927e0237b1ef55e8cd9671f1b6 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Sat, 10 Feb 2024 10:33:15 +0100 Subject: [PATCH] fix: Fixed path strip panic on Windows --- crates/codspeed/src/utils.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/codspeed/src/utils.rs b/crates/codspeed/src/utils.rs index d9cc1a4..cd1dc24 100644 --- a/crates/codspeed/src/utils.rs +++ b/crates/codspeed/src/utils.rs @@ -17,14 +17,16 @@ pub fn get_git_relative_path

(abs_path: P) -> PathBuf where P: AsRef, { - let abs_path = abs_path.as_ref(); - match abs_path - .canonicalize() - .and_then(|p| get_parent_git_repo_path(&p)) - { - Ok(repo_path) => abs_path.strip_prefix(repo_path).unwrap().to_path_buf(), - Err(_) => abs_path.to_path_buf(), + if let Ok(abs_path) = abs_path.as_ref().canonicalize() { + if let Ok(repo_path) = get_parent_git_repo_path(&abs_path) { + return abs_path + .strip_prefix(repo_path) + .expect("Repository path is malformed.") + .to_path_buf(); + } } + + abs_path.as_ref().to_path_buf() } /// Fixes spaces around `::` created by stringify!($function).