Skip to content

Commit 4dd540c

Browse files
committed
Fix overeager warning in list
1 parent 491f253 commit 4dd540c

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,31 @@ pub fn list() -> io::Result<impl Iterator<Item = io::Result<Device>>> {
6565
Err(e) => return Some(Err(e.into())),
6666
};
6767

68+
let name = file.file_name();
69+
if !DEVICE_PREFIXES
70+
.iter()
71+
.any(|p| name.as_bytes().starts_with(p.as_bytes()))
72+
{
73+
// Doesn't match any V4L2 device patterns.
74+
return None;
75+
}
76+
77+
// Sanity check that it's a char device.
6878
match file.file_type() {
6979
Ok(ty) => {
7080
if !ty.is_char_device() {
71-
log::debug!("unexpected device file type {:?}", ty);
81+
log::warn!(
82+
"'{}' is not a character device: {:?}",
83+
name.to_string_lossy(),
84+
ty,
85+
);
7286
return None;
7387
}
7488
}
7589
Err(e) => return Some(Err(e.into())),
7690
}
7791

78-
let name = file.file_name();
79-
if DEVICE_PREFIXES
80-
.iter()
81-
.any(|p| name.as_bytes().starts_with(p.as_bytes()))
82-
{
83-
Some(Device::open(&file.path()))
84-
} else {
85-
None
86-
}
92+
Some(Device::open(&file.path()))
8793
}))
8894
}
8995

0 commit comments

Comments
 (0)