diff --git a/exts/devmaster/src/lib/rules/node.rs b/exts/devmaster/src/lib/rules/node.rs index de600f729daec7c334205f9d5c64351f8122eaf2..502767875ebb8f2f7221773b9ff9f35e3f8573e0 100644 --- a/exts/devmaster/src/lib/rules/node.rs +++ b/exts/devmaster/src/lib/rules/node.rs @@ -874,7 +874,11 @@ mod test { Ok(()) }) { - assert!(e.is_errno(nix::Error::EACCES) || e.is_errno(nix::Error::EBUSY)); + assert!( + e.is_errno(nix::Error::EACCES) + || e.is_errno(nix::Error::EBUSY) + || e.is_errno(nix::Error::EAGAIN) + ); } } diff --git a/libs/device/src/device.rs b/libs/device/src/device.rs index 945bf91b62484355eb515a28af32011444859aee..0104307c3701c8f061ce400a3b8dc7c362dfae65 100644 --- a/libs/device/src/device.rs +++ b/libs/device/src/device.rs @@ -3528,8 +3528,11 @@ mod tests { } if let Err(e) = LoopDev::inner_process("/tmp/test_update_tag", 1024 * 10, inner_test) { - println!("e:{:?}", e); - assert!(e.is_errno(nix::Error::EACCES) || e.is_errno(nix::Error::EBUSY)); + assert!( + e.is_errno(nix::Error::EACCES) + || e.is_errno(nix::Error::EBUSY) + || e.is_errno(nix::Error::EAGAIN) + ); } } diff --git a/libs/event/src/lib.rs b/libs/event/src/lib.rs index c0dd1e4623d0cbc1c8bda3794ba31ed48b805aeb..25e74f861f37f1ac47f6b84ccc23568278bb219a 100644 --- a/libs/event/src/lib.rs +++ b/libs/event/src/lib.rs @@ -572,7 +572,7 @@ mod tests { * Thus the assertion condition should be slightly relaxed. */ let count = *post_s.as_ref().count.borrow(); - assert!(count < 10); + assert!(count >= 1); e.del_source(s).unwrap(); e.del_source(timer_s).unwrap(); diff --git a/libs/hwdb/src/hwdb_util.rs b/libs/hwdb/src/hwdb_util.rs index a5c2eac0e23cd46cb38aa101bde12caae3f26c10..bf0d749ccf589818eeaf54be6db2f9538f27858f 100644 --- a/libs/hwdb/src/hwdb_util.rs +++ b/libs/hwdb/src/hwdb_util.rs @@ -732,10 +732,16 @@ impl HwdbUtil { } match hwdb_bin_dir { - Some(dir) => bin_dir += &dir, - None => bin_dir += "/etc/devmaster/", + Some(dir) => { + if bin_dir.is_empty() { + bin_dir = dir; + } else { + bin_dir = bin_dir + "/" + &dir; + } + } + None => bin_dir += "/etc/devmaster", } - let hwdb_bin = bin_dir.clone() + "hwdb.bin"; + let hwdb_bin = bin_dir.clone() + "/" + "hwdb.bin"; let mut conf_file_dirs: Vec = Vec::new(); if let Some(p) = path { @@ -878,25 +884,97 @@ fn node_lookup(node: Rc>, c: u8) -> Option bool { let mut found: bool = false; - let duration = Duration::from_secs(self.st.st_mtime as u64); + let duration = Duration::new(self.st.st_mtime as u64, self.st.st_mtime_nsec as u32); let st_time = UNIX_EPOCH + duration; let mut time = st_time; @@ -273,7 +273,7 @@ impl SdHwdb { } /// get value by modalias and key - pub fn sd_hwdb_get(&mut self, modalias: String, key: String) -> Result { + pub fn get(&mut self, modalias: String, key: String) -> Result { if let Err(err) = self.properties_prepare(modalias) { return Err(err); } @@ -350,7 +350,7 @@ impl SdHwdb { ); } - if c != search.as_bytes()[i + p] { + if i + p >= search.len() || c != search.as_bytes()[i + p] { return Ok(()); } p += 1; @@ -776,3 +776,33 @@ impl LineBuf { self.rem(1); } } + +#[cfg(test)] +mod tests { + use super::*; + use std::path::Path; + + #[test] + fn test_get() { + for hwdb_bin in HWDB_BIN_PATHS { + if Path::new(hwdb_bin).exists() { + let mut hwdb = SdHwdb::new().unwrap(); + let s = hwdb + .get( + "dmi:bvnLENOVO".to_string(), + "ID_SYSFS_ATTRIBUTE_MODEL".to_string(), + ) + .unwrap(); + assert_eq!(s, "product_version"); + assert_eq!( + hwdb.get( + "invalid_modalias".to_string(), + "ID_SYSFS_ATTRIBUTE_MODEL".to_string() + ), + Err(Errno::ENOENT) + ); + return; + } + } + } +}