@@ -50,30 +50,43 @@ fn component_to_os_str<'a>(
50
50
51
51
impl ToNormalPathComponents for & BStr {
52
52
fn to_normal_path_components ( & self ) -> impl Iterator < Item = Result < & OsStr , to_normal_path_components:: Error > > {
53
- self . split ( |b| * b == b'/' ) . filter_map ( bytes_component_to_os_str)
53
+ self . split ( |b| * b == b'/' )
54
+ . filter_map ( |c| bytes_component_to_os_str ( c, self ) )
54
55
}
55
56
}
56
57
57
58
impl ToNormalPathComponents for & str {
58
59
fn to_normal_path_components ( & self ) -> impl Iterator < Item = Result < & OsStr , to_normal_path_components:: Error > > {
59
- self . split ( '/' ) . filter_map ( |c| bytes_component_to_os_str ( c. as_bytes ( ) ) )
60
+ self . split ( '/' )
61
+ . filter_map ( |c| bytes_component_to_os_str ( c. as_bytes ( ) , ( * self ) . into ( ) ) )
60
62
}
61
63
}
62
64
63
65
impl ToNormalPathComponents for & BString {
64
66
fn to_normal_path_components ( & self ) -> impl Iterator < Item = Result < & OsStr , to_normal_path_components:: Error > > {
65
- self . split ( |b| * b == b'/' ) . filter_map ( bytes_component_to_os_str)
67
+ self . split ( |b| * b == b'/' )
68
+ . filter_map ( |c| bytes_component_to_os_str ( c, self . as_bstr ( ) ) )
66
69
}
67
70
}
68
71
69
- fn bytes_component_to_os_str ( component : & [ u8 ] ) -> Option < Result < & OsStr , to_normal_path_components:: Error > > {
72
+ fn bytes_component_to_os_str < ' a > (
73
+ component : & ' a [ u8 ] ,
74
+ path : & BStr ,
75
+ ) -> Option < Result < & ' a OsStr , to_normal_path_components:: Error > > {
70
76
if component. is_empty ( ) {
71
77
return None ;
72
78
}
73
- gix_path:: try_from_byte_slice ( component. as_bstr ( ) )
79
+ let component = match gix_path:: try_from_byte_slice ( component. as_bstr ( ) )
74
80
. map_err ( |_| to_normal_path_components:: Error :: IllegalUtf8 )
75
- . map ( Path :: as_os_str)
76
- . into ( )
81
+ {
82
+ Ok ( c) => c,
83
+ Err ( err) => return Some ( Err ( err) ) ,
84
+ } ;
85
+ let component = component. components ( ) . next ( ) ?;
86
+ Some ( component_to_os_str (
87
+ component,
88
+ gix_path:: try_from_byte_slice ( path. as_ref ( ) ) . ok ( ) ?,
89
+ ) )
77
90
}
78
91
79
92
/// Access
0 commit comments