From 0f5ce5efb2aa07f7dad3630f16e14ff78dfad822 Mon Sep 17 00:00:00 2001 From: rpschoenburg Date: Mon, 6 Jan 2025 15:40:27 -0800 Subject: [PATCH] temp fix for path_relative_to_dir on Windows --- src/lib/src/util/fs.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/src/util/fs.rs b/src/lib/src/util/fs.rs index e1c536382..0f793c713 100644 --- a/src/lib/src/util/fs.rs +++ b/src/lib/src/util/fs.rs @@ -1345,14 +1345,15 @@ pub fn path_relative_to_dir( path: impl AsRef, dir: impl AsRef, ) -> Result { - let path = path.as_ref(); - let dir = dir.as_ref(); + let path = to_lowercase_path(path.as_ref()); + let dir = to_lowercase_path(dir.as_ref()); let mut mut_path = path.to_path_buf(); let mut components: Vec = vec![]; while mut_path.parent().is_some() { - // println!("Comparing {:?} => {:?} => {:?}", path, mut_path.parent(), dir); + //log::debug!("Comparing {:?} => {:?} => {:?}", path, mut_path.parent(), dir); if let Some(filename) = mut_path.file_name() { + if mut_path != dir { components.push(PathBuf::from(filename)); } else { @@ -1530,6 +1531,13 @@ pub fn to_unix_str(path: impl AsRef) -> String { .replace('\\', "/") } +pub fn to_lowercase_path(path: impl AsRef) -> PathBuf { + PathBuf::from(path.as_ref() + .to_str() + .unwrap_or_default() + .to_lowercase()) +} + pub fn is_glob_path(path: impl AsRef) -> bool { let glob_chars = ['*', '?', '[', ']']; glob_chars