Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libstd/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {

/// Returns a Path that represents the filesystem root that `self` is rooted in.
///
/// If `self` is not absolute, or vol-relative in the case of Windows, this returns None.
/// If `self` is not absolute, or vol/cwd-relative in the case of Windows, this returns None.
fn root_path(&self) -> Option<Self>;

/// Pushes a path (as a byte vector or string) onto `self`.
Expand Down
9 changes: 6 additions & 3 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,12 @@ impl GenericPath for Path {
}

fn root_path(&self) -> Option<Path> {
if self.is_absolute() {
if self.prefix.is_some() {
Some(Path::new(match self.prefix {
Some(VerbatimDiskPrefix)|Some(DiskPrefix) => {
Some(DiskPrefix) if self.is_absolute() => {
self.repr.slice_to(self.prefix_len()+1)
}
Some(VerbatimDiskPrefix) => {
self.repr.slice_to(self.prefix_len()+1)
}
_ => self.repr.slice_to(self.prefix_len())
Expand Down Expand Up @@ -1683,7 +1686,7 @@ mod tests {
fn test_root_path() {
assert_eq!(Path::new("a\\b\\c").root_path(), None);
assert_eq!(Path::new("\\a\\b\\c").root_path(), Some(Path::new("\\")));
assert_eq!(Path::new("C:a").root_path(), None);
assert_eq!(Path::new("C:a").root_path(), Some(Path::new("C:")));
assert_eq!(Path::new("C:\\a").root_path(), Some(Path::new("C:\\")));
assert_eq!(Path::new("\\\\a\\b\\c").root_path(), Some(Path::new("\\\\a\\b")));
assert_eq!(Path::new("\\\\?\\a\\b").root_path(), Some(Path::new("\\\\?\\a")));
Expand Down