Skip to content

Commit

Permalink
Support windows absolute paths in meta almanac
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed May 22, 2024
1 parent ae77ebc commit f7d2b45
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ impl MetaFile {
Ok(())
}
Ok(url) => {
if !url.scheme().starts_with("http") {
// This means it could be either a path with `file:///`, or an absolute path on Windows.
if url.scheme() == "file" {
// Remove the first four characters plus `://`, regardless of case
self.uri = self.uri[7..].to_string();
}
return Ok(());
}
// Build the path for this file.
match url.path_segments().and_then(|segments| segments.last()) {
Some(remote_file_path) => {
Expand Down Expand Up @@ -209,3 +217,39 @@ impl MetaFile {
py.allow_threads(|| self._process())
}
}

#[cfg(test)]
mod ut_metafile {
use super::MetaFile;

#[test]
fn abs_paths() {
let mut window_path = MetaFile {
uri: "C:\\Users\\me\\meta.dhall".to_string(),
crc32: None,
};
assert!(window_path._process().is_ok());
assert_eq!(window_path.uri, "C:\\Users\\me\\meta.dhall".to_string());

let mut file_prefix_path = MetaFile {
uri: "fIlE:///Users/me/meta.dhall".to_string(),
crc32: None,
};
assert!(file_prefix_path._process().is_ok());
assert_eq!(file_prefix_path.uri, "/Users/me/meta.dhall".to_string());

let mut unix_abs_path = MetaFile {
uri: "/Users/me/meta.dhall".to_string(),
crc32: None,
};
assert!(unix_abs_path._process().is_ok());
assert_eq!(unix_abs_path.uri, "/Users/me/meta.dhall".to_string());

let mut unix_rel_path = MetaFile {
uri: "../Users/me/meta.dhall".to_string(),
crc32: None,
};
assert!(unix_rel_path._process().is_ok());
assert_eq!(unix_rel_path.uri, "../Users/me/meta.dhall".to_string());
}
}

0 comments on commit f7d2b45

Please sign in to comment.