From 67065b2a1d0b8050a29623c4d9b87c5d3caf7a38 Mon Sep 17 00:00:00 2001 From: m1stadev Date: Sat, 13 Apr 2024 20:52:24 -0500 Subject: [PATCH 1/2] cli: restore: handle error if usbmuxd cannot be connected to if restoring from recovery/DFU mode on a Linux system, there may be a possibiltiy that usbmuxd will not be running --- pymobiledevice3/cli/restore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymobiledevice3/cli/restore.py b/pymobiledevice3/cli/restore.py index 62c1f9fa..52ae1728 100644 --- a/pymobiledevice3/cli/restore.py +++ b/pymobiledevice3/cli/restore.py @@ -11,7 +11,7 @@ from pymobiledevice3 import usbmux from pymobiledevice3.cli.cli_common import print_json, set_verbosity -from pymobiledevice3.exceptions import ConnectionFailedError, IncorrectModeError +from pymobiledevice3.exceptions import ConnectionFailedError, ConnectionFailedToUsbmuxdError, IncorrectModeError from pymobiledevice3.irecv import IRecv from pymobiledevice3.lockdown import LockdownClient, create_using_usbmux from pymobiledevice3.restore.device import Device @@ -47,7 +47,7 @@ def device(ctx, param, value): for device in usbmux.list_devices(): try: lockdown = create_using_usbmux(serial=device.serial, connection_type='USB') - except (ConnectionFailedError, IncorrectModeError): + except (ConnectionFailedError, ConnectionFailedToUsbmuxdError, IncorrectModeError): continue if (ecid is None) or (lockdown.ecid == value): logger.debug('found device') From ef81d4a1b0c68157d3c8e27a7b997bcad5a326cc Mon Sep 17 00:00:00 2001 From: m1stadev Date: Sat, 13 Apr 2024 21:36:53 -0500 Subject: [PATCH 2/2] cli: restore: fix exception not being caught correctly the exception would be getting raised by `usbmux.list_devices()`, not by `create_using_usbmux()` --- pymobiledevice3/cli/restore.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pymobiledevice3/cli/restore.py b/pymobiledevice3/cli/restore.py index 52ae1728..13e126fa 100644 --- a/pymobiledevice3/cli/restore.py +++ b/pymobiledevice3/cli/restore.py @@ -44,16 +44,20 @@ def device(ctx, param, value): ecid = value logger.debug('searching among connected devices via lockdownd') - for device in usbmux.list_devices(): - try: - lockdown = create_using_usbmux(serial=device.serial, connection_type='USB') - except (ConnectionFailedError, ConnectionFailedToUsbmuxdError, IncorrectModeError): - continue - if (ecid is None) or (lockdown.ecid == value): - logger.debug('found device') - return lockdown - else: - continue + try: + for device in usbmux.list_devices(): + try: + lockdown = create_using_usbmux(serial=device.serial, connection_type='USB') + except (ConnectionFailedError, IncorrectModeError): + continue + if (ecid is None) or (lockdown.ecid == value): + logger.debug('found device') + return lockdown + else: + continue + except ConnectionFailedToUsbmuxdError: + pass + logger.debug('waiting for device to be available in Recovery mode') return IRecv(ecid=ecid)