Skip to content

Commit

Permalink
Merge pull request #947 from doronz88/bugfix/tunnel-option-close
Browse files Browse the repository at this point in the history
cli_common: fix closing of non-required tunnel connections (#940)
  • Loading branch information
doronz88 committed Apr 18, 2024
2 parents 2b5621e + f2e0d74 commit 1081b91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pymobiledevice3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def main() -> None:
except DeveloperModeIsNotEnabledError:
logger.error('Developer Mode is disabled. You can try to enable it using: '
'python3 -m pymobiledevice3 amfi enable-developer-mode')
except InvalidServiceError:
if 'developer' in sys.argv and '--tunnel' not in sys.argv:
sys.argv += ['--tunnel', '']
except InvalidServiceError as e:
logger.warning('Trying again over tunneld since it is a developer command')
if (e.identifier is not None) and ('developer' in sys.argv) and ('--tunnel' not in sys.argv):
sys.argv += ['--tunnel', e.identifier]
return main()
logger.error(INVALID_SERVICE_MESSAGE)
except NoDeviceSelectedError:
Expand Down
2 changes: 1 addition & 1 deletion pymobiledevice3/cli/cli_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def tunneld(self, ctx, param: str, udid: Optional[str] = None) -> Optional[Remot
for rsd in rsds:
if rsd == self.service_provider:
continue
rsd.close()
get_asyncio_loop().run_until_complete(rsd.close())

return self.service_provider

Expand Down
5 changes: 4 additions & 1 deletion pymobiledevice3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ class DeveloperModeError(PyMobileDevice3Exception):

class LockdownError(PyMobileDevice3Exception):
""" lockdown general error """
pass

def __init__(self, message: str, identifier: Optional[str] = None) -> None:
super().__init__(message)
self.identifier = identifier


class GetProhibitedError(LockdownError):
Expand Down
4 changes: 2 additions & 2 deletions pymobiledevice3/lockdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,11 @@ def _request(self, request: str, options: Mapping = None, verify_request: bool =
'MissingValue': MissingValueError,
'InvalidService': InvalidServiceError,
'InvalidConnection': InvalidConnectionError, }
raise exception_errors.get(error, LockdownError)(error)
raise exception_errors.get(error, LockdownError)(error, self.identifier)

# iOS < 5: 'Error' is not present, so we need to check the 'Result' instead
if response.get('Result') == 'Failure':
raise LockdownError()
raise LockdownError('', self.identifier)

return response

Expand Down

0 comments on commit 1081b91

Please sign in to comment.