Skip to content

Commit d822a48

Browse files
committed
Register functions in deterministic order
1 parent 72cdefc commit d822a48

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/gadget.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustix::io::Errno;
44
use std::{
5-
collections::{HashMap, HashSet},
5+
collections::HashMap,
66
ffi::{OsStr, OsString},
77
fmt, fs,
88
io::{Error, ErrorKind, Result},
@@ -415,7 +415,12 @@ impl Gadget {
415415
}
416416

417417
let gadget_name = dir.file_name().unwrap().to_string_lossy();
418-
let functions: HashSet<_> = self.configs.iter().flat_map(|c| &c.functions).collect();
418+
let mut functions = Vec::new();
419+
for func in self.configs.iter().flat_map(|c| &c.functions) {
420+
if !functions.contains(&func) {
421+
functions.push(func);
422+
}
423+
}
419424
let mut func_dirs = HashMap::new();
420425
for (func_idx, &func) in functions.iter().enumerate() {
421426
let func_dir = dir.join(
@@ -447,6 +452,7 @@ impl Gadget {
447452
let config_dir = config_dirs.get(os_desc.config).ok_or_else(|| {
448453
Error::new(ErrorKind::InvalidInput, "invalid configuration index in OS descriptor")
449454
})?;
455+
log::debug!("linking OS descriptor to config dir {}", config_dir.display());
450456
symlink(config_dir, os_desc_dir.join(config_dir.file_name().unwrap()))?;
451457
} else {
452458
log::warn!("USB OS descriptor is unsupported by kernel");

0 commit comments

Comments
 (0)