Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Feb 13, 2025
1 parent d14cbf8 commit dc41e88
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions shared/tree-sitter-extractor/src/file_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ pub fn normalize_path(path: &Path) -> String {
// have to do a bit of work removing certain prefixes and replacing
// backslashes.
let mut components: Vec<String> = Vec::new();
let mut is_disk = false;
for component in path.components() {
let mut path_components = path.components().peekable();
while let Some(component) = path_components.next() {
match component {
std::path::Component::Prefix(prefix) => match prefix.kind() {
std::path::Prefix::Disk(letter) | std::path::Prefix::VerbatimDisk(letter) => {
is_disk = true;
components.push(format!("{}:", letter as char));
}
std::path::Prefix::Verbatim(x) | std::path::Prefix::DeviceNS(x) => {
Expand All @@ -28,16 +27,17 @@ pub fn normalize_path(path: &Path) -> String {
std::path::Component::Normal(n) => {
components.push(n.to_string_lossy().to_string());
}
std::path::Component::RootDir => {}
std::path::Component::RootDir => {
if path_components.peek().is_none() {
// The path points at a root directory, so we need to add a
// trailing slash, e.g. `C:/` instead of `C:`.
components.push("".to_string());
}
}
std::path::Component::CurDir => {}
std::path::Component::ParentDir => {}
}
}
if components.len() == 1 && is_disk {
// If the path is just a drive letter, we need to add a trailing
// slash to match the CodeQL spec.
components.push("".to_string());
}
components.join("/")
} else {
// For other operating systems, we can use the canonicalized path
Expand Down

0 comments on commit dc41e88

Please sign in to comment.