File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed
Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -29,24 +29,16 @@ See https://aboutcode.org for more information about nexB OSS projects.
2929//!
3030
3131use fst:: Set ;
32- use memmap2 :: Mmap ;
32+
3333use once_cell:: sync:: Lazy ;
3434use std:: env;
35- use std:: fs:: File ;
36- use std:: path:: Path ;
3735
38- static VALIDATOR : Lazy < Set < Mmap > > = Lazy :: new ( || {
39- let path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "purls.fst" ) ;
40- load_fst ( & path)
41- } ) ;
36+ static FST_DATA : & [ u8 ] = include_bytes ! ( concat!( env!( "OUT_DIR" ) , "/purls.fst" ) ) ;
4237
43- fn load_fst ( path : & Path ) -> Set < Mmap > {
44- let file = File :: open ( path) . expect ( "Failed to open FST file" ) ;
45- let mmap = unsafe { Mmap :: map ( & file) . expect ( "Failed to mmap FST file" ) } ;
46- Set :: new ( mmap) . expect ( "Failed to load FST from mmap" )
47- }
38+ static VALIDATOR : Lazy < Set < & ' static [ u8 ] > > =
39+ Lazy :: new ( || Set :: new ( FST_DATA ) . expect ( "Failed to load FST from embedded bytes" ) ) ;
4840
49- fn strip_and_check_purl ( packageurl : & str , fst_map : & Set < Mmap > ) -> bool {
41+ fn strip_and_check_purl ( packageurl : & str , fst_map : & Set < & [ u8 ] > ) -> bool {
5042 let trimmed_packageurl = packageurl. trim_end_matches ( "/" ) ;
5143 fst_map. contains ( trimmed_packageurl)
5244}
Original file line number Diff line number Diff line change @@ -10,13 +10,16 @@ See https://aboutcode.org for more information about nexB OSS projects.
1010*/
1111
1212use super :: * ;
13+ use fst:: Set ;
14+ use std:: fs;
1315use std:: path:: Path ;
1416
1517#[ test]
1618fn test_validate_with_custom_file ( ) {
1719 let test_path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/data/test_purls.fst" ) ;
18- let validator = load_fst ( & test_path) ;
19-
20+ let data: Vec < u8 > = fs:: read ( test_path) . unwrap ( ) ;
21+ let data_slice: & [ u8 ] = & data;
22+ let validator = Set :: new ( data_slice) . unwrap ( ) ;
2023 assert ! ( strip_and_check_purl(
2124 "pkg:nuget/FluentUtils.EnumExtensions" ,
2225 & validator
@@ -27,7 +30,9 @@ fn test_validate_with_custom_file() {
2730#[ test]
2831fn test_validate_with_packageurl_trailing_slash ( ) {
2932 let test_path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/data/test_purls.fst" ) ;
30- let validator = load_fst ( & test_path) ;
33+ let data: Vec < u8 > = fs:: read ( test_path) . unwrap ( ) ;
34+ let data_slice: & [ u8 ] = & data;
35+ let validator = Set :: new ( data_slice) . unwrap ( ) ;
3136
3237 assert ! ( validator. contains( "pkg:nuget/FluentUtils.EnumExtensions" ) ) ;
3338 assert ! ( strip_and_check_purl(
You can’t perform that action at this time.
0 commit comments