Skip to content

Commit

Permalink
Merge branch 'main' into udev-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Nov 22, 2023
2 parents 12914d2 + d671571 commit 52cfae4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
on: [push, pull_request]
on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
workflow_dispatch:

name: Test, build and package

Expand Down Expand Up @@ -62,6 +69,15 @@ jobs:
if: matrix.job.use-cross == true
run: cargo install cross

- name: Format and clippy
id: format
shell: bash
if: matrix.job.use-cross == false
run: |
cargo fmt -- --check
cargo clippy --all-targets -- -Dwarnings
cargo clippy --all-targets --all-features -- -Dwarnings
- name: Test
id: test
shell: bash
Expand Down
24 changes: 10 additions & 14 deletions src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ pub struct UdevInfo {
/// ```
pub fn get_udev_info(port_path: &str) -> Result<UdevInfo, Error> {
let path: String = format!("/sys/bus/usb/devices/{}", port_path);
let device = udevlib::Device::from_syspath(&Path::new(&path)).map_err(|e| {
let device = udevlib::Device::from_syspath(Path::new(&path)).map_err(|e| {
Error::new(
ErrorKind::Udev,
&format!(
"Failed to get udev info for device at {}: Error({})",
path,
e.to_string()
path, e
),
)
})?;
Expand All @@ -54,13 +53,12 @@ pub fn get_udev_info(port_path: &str) -> Result<UdevInfo, Error> {
/// ```
pub fn get_udev_driver_name(port_path: &str) -> Result<Option<String>, Error> {
let path: String = format!("/sys/bus/usb/devices/{}", port_path);
let device = udevlib::Device::from_syspath(&Path::new(&path)).map_err(|e| {
let device = udevlib::Device::from_syspath(Path::new(&path)).map_err(|e| {
Error::new(
ErrorKind::Udev,
&format!(
"Failed to get udev info for device at {}: Error({})",
path,
e.to_string()
path, e
),
)
})?;
Expand All @@ -79,13 +77,12 @@ pub fn get_udev_driver_name(port_path: &str) -> Result<Option<String>, Error> {
/// ```
pub fn get_udev_syspath(port_path: &str) -> Result<Option<String>, Error> {
let path: String = format!("/sys/bus/usb/devices/{}", port_path);
let device = udevlib::Device::from_syspath(&Path::new(&path)).map_err(|e| {
let device = udevlib::Device::from_syspath(Path::new(&path)).map_err(|e| {
Error::new(
ErrorKind::Udev,
&format!(
"Failed to get udev info for device at {}: Error({})",
path,
e.to_string()
path, e
),
)
})?;
Expand All @@ -112,14 +109,12 @@ pub fn get_udev_attribute<T: AsRef<std::ffi::OsStr> + std::fmt::Display>(
attribute: T,
) -> Result<Option<String>, Error> {
let path: String = format!("/sys/bus/usb/devices/{}", port_path);
let device = udevlib::Device::from_syspath(&Path::new(&path)).map_err(|e| {
let device = udevlib::Device::from_syspath(Path::new(&path)).map_err(|e| {
Error::new(
ErrorKind::Udev,
&format!(
"Failed to get udev attribute {} for device at {}: Error({})",
attribute,
path,
e.to_string()
attribute, path, e
),
)
})?;
Expand Down Expand Up @@ -160,6 +155,7 @@ pub mod hwdb {
)
})?;


Ok(hwdb
.query_one(&modalias.to_string(), &key.to_string())
.map(|s| s.to_str().unwrap_or("").to_string()))
Expand All @@ -176,7 +172,7 @@ mod tests {
fn test_udev_info() {
let udevi = get_udev_info("1-0:1.0").unwrap();
assert_eq!(udevi.driver, Some("hub".into()));
assert_eq!(udevi.syspath.unwrap().contains("usb1/1-0:1.0"), true);
assert!(udevi.syspath.unwrap().contains("usb1/1-0:1.0"));
}

/// Tests can lookup bInterfaceClass of the root hub, which is always 09
Expand Down

0 comments on commit 52cfae4

Please sign in to comment.