Skip to content

Commit 60feb96

Browse files
committed
progress
1 parent 856dc29 commit 60feb96

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

crates/pgt_workspace/src/configuration.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,24 +449,44 @@ impl PartialConfigurationExt for PartialConfiguration {
449449
/// Normalizes a path, resolving '..' and '.' segments without requiring the path to exist
450450
fn normalize_path(path: &Path) -> PathBuf {
451451
let mut components = Vec::new();
452+
let mut has_root_or_prefix = false;
453+
452454
for component in path.components() {
453455
match component {
454456
std::path::Component::ParentDir => {
455-
if !components.is_empty() {
457+
if !components.is_empty()
458+
&& !matches!(components.last(), Some(c) if matches!(Path::new(c).components().next(),
459+
Some(std::path::Component::Prefix(_))))
460+
{
456461
components.pop();
457462
}
458463
}
459464
std::path::Component::Normal(c) => components.push(c),
460465
std::path::Component::CurDir => {}
461-
c @ std::path::Component::RootDir | c @ std::path::Component::Prefix(_) => {
466+
c @ std::path::Component::RootDir => {
467+
has_root_or_prefix = true;
468+
components.clear();
469+
components.push(c.as_os_str());
470+
}
471+
c @ std::path::Component::Prefix(_) => {
472+
has_root_or_prefix = true;
462473
components.clear();
463474
components.push(c.as_os_str());
464475
}
465476
}
466477
}
467478

468479
if components.is_empty() {
469-
PathBuf::from("/")
480+
if has_root_or_prefix {
481+
// On Windows, this would be something like "C:\" or "\"
482+
path.ancestors()
483+
.last()
484+
.unwrap_or(Path::new(""))
485+
.to_path_buf()
486+
} else {
487+
// Return current directory as a relative path
488+
PathBuf::from(".")
489+
}
470490
} else {
471491
let mut result = PathBuf::new();
472492
for component in components {

0 commit comments

Comments
 (0)