1
1
use super :: {
2
- discovery_impl:: { do_parse_and_find, get_device_relatives , DeviceProperties } ,
2
+ discovery_impl:: { do_parse_and_find, insert_device_with_relatives , DeviceProperties } ,
3
3
wrappers:: udev_enumerator,
4
4
} ;
5
5
use akri_discovery_utils:: discovery:: {
@@ -12,7 +12,7 @@ use akri_discovery_utils::discovery::{
12
12
} ;
13
13
use async_trait:: async_trait;
14
14
use log:: { error, info, trace} ;
15
- use std:: collections:: HashMap ;
15
+ use std:: collections:: { HashMap , HashSet } ;
16
16
use std:: time:: Duration ;
17
17
use tokio:: sync:: mpsc;
18
18
use tokio:: time:: sleep;
@@ -71,28 +71,15 @@ impl DiscoveryHandler for DiscoveryHandlerImpl {
71
71
}
72
72
break ;
73
73
}
74
- let mut devpaths: HashMap < String , Vec < DeviceProperties > > = HashMap :: new ( ) ;
74
+ let mut devpaths: HashMap < String , HashSet < DeviceProperties > > = HashMap :: new ( ) ;
75
75
udev_rules. iter ( ) . for_each ( |rule| {
76
76
let enumerator = udev_enumerator:: create_enumerator ( ) ;
77
77
let paths = do_parse_and_find ( enumerator, rule) . unwrap ( ) ;
78
78
for path in paths. into_iter ( ) {
79
79
if !discovery_handler_config. group_recursive {
80
- devpaths. insert ( path. 0 . clone ( ) , vec ! [ path] ) ;
80
+ devpaths. insert ( path. 0 . clone ( ) , HashSet :: from ( [ path] ) ) ;
81
81
} else {
82
- match get_device_relatives ( & path. 0 , devpaths. keys ( ) ) {
83
- ( Some ( parent) , _) => devpaths. get_mut ( & parent) . unwrap ( ) . push ( path) ,
84
- ( None , children) => {
85
- let id = path. 0 . clone ( ) ;
86
- let mut children_devices: Vec < DeviceProperties > = children
87
- . into_iter ( )
88
- . flat_map ( |child| {
89
- devpaths. remove ( & child) . unwrap ( ) . into_iter ( )
90
- } )
91
- . collect ( ) ;
92
- children_devices. push ( path) ;
93
- let _ = devpaths. insert ( id, children_devices) ;
94
- }
95
- }
82
+ insert_device_with_relatives ( & mut devpaths, path) ;
96
83
}
97
84
}
98
85
} ) ;
0 commit comments