File tree 2 files changed +7
-4
lines changed
2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
400
400
401
401
/// Returns a Path that represents the filesystem root that `self` is rooted in.
402
402
///
403
- /// If `self` is not absolute, or vol-relative in the case of Windows, this returns None.
403
+ /// If `self` is not absolute, or vol/cwd -relative in the case of Windows, this returns None.
404
404
fn root_path ( & self ) -> Option < Self > ;
405
405
406
406
/// Pushes a path (as a byte vector or string) onto `self`.
Original file line number Diff line number Diff line change @@ -432,9 +432,12 @@ impl GenericPath for Path {
432
432
}
433
433
434
434
fn root_path ( & self ) -> Option < Path > {
435
- if self . is_absolute ( ) {
435
+ if self . prefix . is_some ( ) {
436
436
Some ( Path :: new ( match self . prefix {
437
- Some ( VerbatimDiskPrefix ) |Some ( DiskPrefix ) => {
437
+ Some ( DiskPrefix ) if self . is_absolute ( ) => {
438
+ self . repr . slice_to ( self . prefix_len ( ) +1 )
439
+ }
440
+ Some ( VerbatimDiskPrefix ) => {
438
441
self . repr . slice_to ( self . prefix_len ( ) +1 )
439
442
}
440
443
_ => self . repr . slice_to ( self . prefix_len ( ) )
@@ -1688,7 +1691,7 @@ mod tests {
1688
1691
fn test_root_path( ) {
1689
1692
assert_eq!( Path :: new( "a\\ b\\ c" ) . root_path( ) , None ) ;
1690
1693
assert_eq!( Path :: new( "\\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ " ) ) ) ;
1691
- assert_eq!( Path :: new( "C:a" ) . root_path( ) , None ) ;
1694
+ assert_eq!( Path :: new( "C:a" ) . root_path( ) , Some ( Path :: new ( "C:" ) ) ) ;
1692
1695
assert_eq!( Path :: new( "C:\\ a" ) . root_path( ) , Some ( Path :: new( "C:\\ " ) ) ) ;
1693
1696
assert_eq!( Path :: new( "\\ \\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ \\ a\\ b" ) ) ) ;
1694
1697
assert_eq!( Path :: new( "\\ \\ ?\\ a\\ b" ) . root_path( ) , Some ( Path :: new( "\\ \\ ?\\ a" ) ) ) ;
You can’t perform that action at this time.
0 commit comments