From fa7d8e30daef719461ad7e7de7c80144db99393e Mon Sep 17 00:00:00 2001 From: shastry Date: Sun, 20 Sep 2020 14:35:06 +0530 Subject: [PATCH] Nested loop continue logic fix Continue the outer loop, break of the inner loop. Else you get a usb_dir NoneType exception in os.path.join if there's a device without idProduct, idVendor, bcdDevice sysfs files. ``` Unable to open device Traceback (most recent call last): File "/usr/lib/calibre/calibre/gui2/device.py", line 201, in do_connect dev.open(detected_device, self.current_library_uuid) File "/usr/lib/calibre/calibre/devices/usbms/device.py", line 809, in open self.open_linux() File "/usr/lib/calibre/calibre/devices/usbms/device.py", line 560, in open_linux main, carda, cardb = self.find_device_nodes() File "/usr/lib/calibre/calibre/devices/usbms/device.py", line 471, in find_device_nodes ven, prod, bcd = map(e, ('idVendor', 'idProduct', 'bcdDevice')) File "/usr/lib/calibre/calibre/devices/usbms/device.py", line 470, in e = lambda q : raw2num(open(j(usb_dir, q), 'rb').read().decode('utf-8')) File "/usr/lib/python2.7/posixpath.py", line 70, in join elif path == '' or path.endswith('/'): AttributeError: 'NoneType' object has no attribute 'endswith' ``` --- src/calibre/devices/usbms/device.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index c2e5dad67f..6cd2417539 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -466,7 +466,9 @@ class Device(DeviceConfig, DevicePlugin): for y in ('idProduct', 'idVendor', 'bcdDevice'): if not os.access(j(usb_dir, y), os.R_OK): usb_dir = None - continue + break + if usb_dir is None: + continue e = lambda q : raw2num(open(j(usb_dir, q), 'rb').read().decode('utf-8')) ven, prod, bcd = map(e, ('idVendor', 'idProduct', 'bcdDevice')) if not (test(ven, 'idVendor') and test(prod, 'idProduct') and