File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use path_abs::PathAbs;
2
2
use std:: {
3
3
fmt:: { self , Display } ,
4
4
io,
5
- path:: { Path , PathBuf } ,
5
+ path:: { Component , Path , PathBuf } ,
6
6
} ;
7
7
use thiserror:: Error ;
8
8
@@ -84,7 +84,33 @@ impl Display for PathNotPrefixed {
84
84
}
85
85
86
86
pub fn prefix_path ( root : impl AsRef < Path > , path : impl AsRef < Path > ) -> PathBuf {
87
- root. as_ref ( ) . join ( path)
87
+ let root = root. as_ref ( ) ;
88
+ let path = path. as_ref ( ) ;
89
+ let is_verbatim = if let Some ( Component :: Prefix ( prefix) ) = root. components ( ) . next ( ) {
90
+ prefix. kind ( ) . is_verbatim ( )
91
+ } else {
92
+ false
93
+ } ;
94
+ if !is_verbatim {
95
+ return root. join ( path) ;
96
+ }
97
+ let mut buf = root. components ( ) . collect :: < Vec < _ > > ( ) ;
98
+ for component in path. components ( ) {
99
+ match component {
100
+ Component :: RootDir => {
101
+ buf. truncate ( 1 ) ;
102
+ buf. push ( component) ;
103
+ }
104
+ Component :: CurDir => { }
105
+ Component :: ParentDir => {
106
+ if let Some ( _) = buf. last ( ) {
107
+ buf. pop ( ) ;
108
+ }
109
+ }
110
+ _ => buf. push ( component) ,
111
+ } ;
112
+ }
113
+ buf. into_iter ( ) . collect ( )
88
114
}
89
115
90
116
pub fn unprefix_path (
You can’t perform that action at this time.
0 commit comments