Skip to content

Commit

Permalink
Merge pull request #244 from nyx-space/242-issues-with-absolute-paths…
Browse files Browse the repository at this point in the history
…-in-metaalmanac-on-windows

Support windows absolute paths in meta almanac
  • Loading branch information
ChristopherRabotin committed May 22, 2024
2 parents ae77ebc + 89eb11c commit 81d534a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
target: [x86_64, x86, aarch64, armv7, ppc64le]
steps:
- uses: actions/checkout@v4

Expand Down
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 81d534a

Please sign in to comment.