@@ -186,6 +186,20 @@ pub(crate) fn read_files(files_path: &Path) -> Result<Vec<String>> {
186186 Ok ( vec)
187187}
188188
189+ fn get_prefix < ' a > ( prefix : & ' a str , to_check : & ' a str ) -> Result < String > {
190+ let mut s1 = prefix. split ( '/' ) . collect :: < Vec < & str > > ( ) ;
191+ let mut s2 = to_check. split ( '/' ) . collect :: < Vec < & str > > ( ) ;
192+ s1. pop ( ) ;
193+ while let Some ( s) = s2. pop ( ) {
194+ if let Some ( last) = s1. last ( ) {
195+ if * last == s {
196+ s1. pop ( ) ;
197+ }
198+ }
199+ }
200+ Ok ( s1. join ( "/" ) + "/" )
201+ }
202+
189203// This function read the content of the coveralls json file obtain by using grcov
190204// Return a HashMap with all the files arrays of covered lines using the path to the file as key
191205pub ( crate ) fn read_json ( file : String , prefix : & str ) -> Result < HashMap < String , Vec < Value > > > {
@@ -196,7 +210,9 @@ pub(crate) fn read_json(file: String, prefix: &str) -> Result<HashMap<String, Ve
196210 . ok_or ( Error :: ReadingJSONError ( ) ) ?;
197211 let mut covs = HashMap :: < String , Vec < Value > > :: new ( ) ;
198212 vec. iter ( ) . try_for_each ( |x| -> Result < ( ) > {
199- let name = Path :: new ( prefix) . join ( x[ "name" ] . as_str ( ) . ok_or ( Error :: PathConversionError ( ) ) ?) ;
213+ let n = x[ "name" ] . as_str ( ) . ok_or ( Error :: PathConversionError ( ) ) ?;
214+ let prefix = get_prefix ( prefix, n) ?;
215+ let name = Path :: new ( & prefix) . join ( x[ "name" ] . as_str ( ) . ok_or ( Error :: PathConversionError ( ) ) ?) ;
200216 let value = x[ "coverage" ]
201217 . as_array ( )
202218 . ok_or ( Error :: ConversionError ( ) ) ?
@@ -275,7 +291,8 @@ pub(crate) fn read_json_covdir(file: String, map_prefix: &str) -> Result<HashMap
275291 . ok_or ( Error :: ConversionError ( ) ) ?,
276292 } ;
277293 let name_path = format ! ( "{}/{}" , prefix, key) ;
278- res. insert ( map_prefix. to_owned ( ) + name_path. as_str ( ) , covdir) ;
294+ let map_prefix = get_prefix ( map_prefix, name_path. as_str ( ) ) ?;
295+ res. insert ( map_prefix + name_path. as_str ( ) , covdir) ;
279296 }
280297 Ok ( ( ) )
281298 } ) ?;
0 commit comments