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 @@ -386,7 +386,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
386
386
387
387
/// Returns a Path that represents the filesystem root that `self` is rooted in.
388
388
///
389
- /// If `self` is not absolute, or vol-relative in the case of Windows, this returns None.
389
+ /// If `self` is not absolute, or vol/cwd -relative in the case of Windows, this returns None.
390
390
fn root_path ( & self ) -> Option < Self > ;
391
391
392
392
/// 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 ( ) )
@@ -1683,7 +1686,7 @@ mod tests {
1683
1686
fn test_root_path( ) {
1684
1687
assert_eq!( Path :: new( "a\\ b\\ c" ) . root_path( ) , None ) ;
1685
1688
assert_eq!( Path :: new( "\\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ " ) ) ) ;
1686
- assert_eq!( Path :: new( "C:a" ) . root_path( ) , None ) ;
1689
+ assert_eq!( Path :: new( "C:a" ) . root_path( ) , Some ( Path :: new ( "C:" ) ) ) ;
1687
1690
assert_eq!( Path :: new( "C:\\ a" ) . root_path( ) , Some ( Path :: new( "C:\\ " ) ) ) ;
1688
1691
assert_eq!( Path :: new( "\\ \\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ \\ a\\ b" ) ) ) ;
1689
1692
assert_eq!( Path :: new( "\\ \\ ?\\ a\\ b" ) . root_path( ) , Some ( Path :: new( "\\ \\ ?\\ a" ) ) ) ;
You can’t perform that action at this time.
0 commit comments