Skip to content

Commit

Permalink
cli: afc: add -i/--ignore-errors option to pull
Browse files Browse the repository at this point in the history
  • Loading branch information
0xepsil0n authored Nov 18, 2024
1 parent 11cc5e1 commit b2b7b9d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pymobiledevice3/cli/afc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def afc_shell(service_provider: LockdownClient):


@afc.command('pull', cls=Command)
@click.option('-i', '--ignore-errors', is_flag=True, help='Ignore AFC pull errors')
@click.argument('remote_file', type=click.Path(exists=False))
@click.argument('local_file', type=click.Path(exists=False))
def afc_pull(service_provider: LockdownServiceProvider, remote_file: str, local_file: str) -> None:
def afc_pull(service_provider: LockdownServiceProvider, remote_file: str, local_file: str, ignore_errors: bool) -> None:
""" pull remote file from /var/mobile/Media """
AfcService(lockdown=service_provider).pull(remote_file, local_file)
AfcService(lockdown=service_provider).pull(remote_file, local_file, ignore_errors=ignore_errors)


@afc.command('push', cls=Command)
Expand Down
23 changes: 15 additions & 8 deletions pymobiledevice3/services/afc.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def __init__(self, lockdown: LockdownServiceProvider, service_name: str = None):
self.packet_num = 0

def pull(self, relative_src: str, dst: str, match: Optional[Pattern] = None, callback: Optional[Callable] = None,
src_dir: str = '') -> None:
src_dir: str = '', ignore_errors: bool = False) -> None:
src = self.resolve_path(posixpath.join(src_dir, relative_src))

if not self.isdir(src):
Expand Down Expand Up @@ -260,12 +260,18 @@ def pull(self, relative_src: str, dst: str, match: Optional[Pattern] = None, cal
if match is not None and not match.match(posixpath.basename(src_filename)):
continue

if self.isdir(src_filename):
dst_filename.mkdir(exist_ok=True)
self.pull(src_filename, str(dst_path), callback=callback)
continue
try:
if self.isdir(src_filename):
dst_filename.mkdir(exist_ok=True)
self.pull(src_filename, str(dst_path), callback=callback, ignore_errors=ignore_errors)
continue

self.pull(src_filename, str(dst_path), callback=callback, ignore_errors=ignore_errors)

self.pull(src_filename, str(dst_path), callback=callback)
except Exception as afc_exception:
if not ignore_errors:
raise
self.logger.warning("(Ignoring) Error:", afc_exception, "occured during the copy of", src_filename)

@path_to_str()
def exists(self, filename):
Expand Down Expand Up @@ -863,11 +869,12 @@ def _do_rm(self, file: Annotated[list[str], Arg(nargs='+', completer=path_comple
for filename in file:
self.afc.rm(self.relative_path(filename))

def _do_pull(self, remote_path: Annotated[str, Arg(completer=path_completer)], local_path: str):
def _do_pull(self, remote_path: Annotated[str, Arg(completer=path_completer)], local_path: str,
ignore_errors: bool = False):
def log(src, dst):
print(f'{src} --> {dst}')

self.afc.pull(remote_path, local_path, callback=log, src_dir=self.cwd)
self.afc.pull(remote_path, local_path, callback=log, src_dir=self.cwd, ignore_errors=ignore_errors)

def _do_push(self, local_path: str, remote_path: Annotated[str, Arg(completer=path_completer)]):
def log(src, dst):
Expand Down

0 comments on commit b2b7b9d

Please sign in to comment.