Skip to content

Commit

Permalink
temp fix for path_relative_to_dir on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rpschoenburg committed Jan 6, 2025
1 parent 2f90d54 commit 0f5ce5e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/src/util/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,14 +1345,15 @@ pub fn path_relative_to_dir(
path: impl AsRef<Path>,
dir: impl AsRef<Path>,
) -> Result<PathBuf, OxenError> {
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<PathBuf> = 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 {
Expand Down Expand Up @@ -1530,6 +1531,13 @@ pub fn to_unix_str(path: impl AsRef<Path>) -> String {
.replace('\\', "/")
}

pub fn to_lowercase_path(path: impl AsRef<Path>) -> PathBuf {
PathBuf::from(path.as_ref()
.to_str()
.unwrap_or_default()
.to_lowercase())
}

pub fn is_glob_path(path: impl AsRef<Path>) -> bool {
let glob_chars = ['*', '?', '[', ']'];
glob_chars
Expand Down

0 comments on commit 0f5ce5e

Please sign in to comment.