Skip to content

Commit

Permalink
Fix Linux HID device cache (fixes #595)
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Feb 27, 2024
1 parent ce7fd08 commit 5780253
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions ykman/hid/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def get_usage(dev):


def list_devices():
stale = set(_failed_cache)
devices = []
for hidraw in glob.glob("/dev/hidraw*"):
stale.discard(hidraw)
try:
with open(hidraw, "rb") as f:
bustype, vid, pid = get_info(f)
if vid == YUBICO_VID and get_usage(f) == USAGE_OTP:
devices.append(OtpYubiKeyDevice(hidraw, pid, HidrawConnection))
if hidraw in _failed_cache:
_failed_cache.remove(hidraw)
except Exception:
if hidraw not in _failed_cache:
logger.debug(
Expand All @@ -126,7 +126,4 @@ def list_devices():
_failed_cache.add(hidraw)
continue

# Remove entries from the cache that were not seen
_failed_cache.difference_update(hidraw)

return devices

0 comments on commit 5780253

Please sign in to comment.