Skip to content

Commit

Permalink
udevrs fixes integrated; hwdb lookup working
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Jun 21, 2024
1 parent fa9416b commit d788a42
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "List system USB buses and devices; a modern cross-platform `lsusb
repository = "https://github.com/tuna-f1sh/cyme"
readme = "README.md"
license = "GPL-3.0-or-later"
version = "1.6.1"
version = "1.7.0"
edition = "2021"
keywords = ["usb", "lsusb", "system_profiler", "macos", "libusb"]
categories = ["command-line-utilities"]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ pub mod icon;
pub mod lsusb;
pub mod system_profiler;
pub mod types;
pub mod usb;
#[cfg(all(target_os = "linux", feature = "udev"))]
pub mod udev;
#[cfg(all(all(target_os = "linux", feature = "udevlib"), not(feature = "udev")))]
#[path = "udev_ffi.rs"]
pub mod udev;
pub mod usb;

/// Set cyme module and binary log level
pub fn set_log_level(debug: u8) -> crate::error::Result<()> {
Expand Down
15 changes: 4 additions & 11 deletions src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ pub fn get_udev_attribute<T: AsRef<std::ffi::OsStr> + std::fmt::Display + Into<S
)
})?;

Ok(device.get_sysattr_value(&attribute.into()).map(|s| s.trim().to_string()))
Ok(device
.get_sysattr_value(&attribute.into())
.map(|s| s.trim().to_string()))
}

/// Utilities to get device information using udev hwdb - only supported on Linux. Requires 'udev' feature.
Expand Down Expand Up @@ -146,16 +148,7 @@ pub mod hwdb {
)
})?;

hwdb.get_properties_list_entry(&modalias.to_string(), 0)
.map(|mut entry| entry
.find(|entry| entry.name() == key)
.map(|entry| entry.value().to_owned())
).map_err(|e| {
Error::new(
ErrorKind::Udev,
&format!("Failed to get hwdb modalias/key {}/{}: Error({})", modalias, key, e),
)
})
Ok(udevrs::udev_hwdb_query_one(&mut hwdb, modalias, key).map(|s| s.trim().to_string()))
}
}

Expand Down

0 comments on commit d788a42

Please sign in to comment.