JeffLIrion / adb_shell

A Python implementation of ADB with shell and FileSync functionality.
Apache License 2.0
530 stars 60 forks source link

pulling a non-existing file causes an error, which is not handled well. #146

Closed atti92 closed 3 years ago

atti92 commented 3 years ago

Description

After trying to pull a file that doesn't exist, the next command SOMETIMES also fails, because it can't read the packets. I found out there is a packet which tell the reason of the FAIL, but it's not always there when it reads it.

Log

Test code I run:

adb_device = AdbDeviceTcp(IP, PORT, 20)
adb_device.connect(rsa_keys=[signer], auth_timeout_s=30.0)
try:
    adb_device.pull("/data/local/tmp/23124124/", "asd")
except Exception as e:
    print(e)
    traceback.print_exc()
adb_device.push(r"to_upload.tar.gz", "/data/local/tmp/to_upload.tar.gz",
                progress_callback=push_progress_callback, transport_timeout_s=30, read_timeout_s=30)
Command failed: 
Traceback (most recent call last):
    adb_device.pull("/data/local/tmp/23124124/", "asd")
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 548, in pull
    self._pull(device_path, stream, progress_callback, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 575, in _pull
    for cmd_id, _, data in self._filesync_read_until([constants.DATA], [constants.DONE], adb_info, filesync_info):
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1159, in _filesync_read_until
    cmd_id, header, data = self._filesync_read(expected_ids + finish_ids, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1094, in _filesync_read
    raise exceptions.AdbCommandFailureException('Command failed: {}'.format(reason))
adb_shell.exceptions.AdbCommandFailureException: Command failed: 
Traceback (most recent call last):
    progress_callback=push_progress_callback, transport_timeout_s=30, read_timeout_s=30)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 619, in push
    self._open(b'sync:', adb_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 778, in _open
    _, adb_info.remote_id, their_local_id, _ = self._read([constants.OKAY], adb_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 829, in _read
    raise exceptions.InvalidCommandError("Unknown command: %d = '%s' (arg0 = %d, arg1 = %d, msg = '%s')" % (cmd, int_to_cmd(cmd), arg0, arg1, msg))
adb_shell.exceptions.InvalidCommandError: Unknown command: 1852141679 = 'b'open'' (arg0 = 1767990816, arg1 = 979658092, msg = 'b'open failed: No such fil'')

Process finished with exit code 1
atti92 commented 3 years ago

Running the same code with the change I get the following log:

Command failed: open failed: No such file or directory
Traceback (most recent call last):
    adb_device.pull("/data/local/tmp/23124124/", "asd")
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 548, in pull
    self._pull(device_path, stream, progress_callback, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 575, in _pull
    for cmd_id, _, data in self._filesync_read_until([constants.DATA], [constants.DONE], adb_info, filesync_info):
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1149, in _filesync_read_until
    cmd_id, header, data = self._filesync_read(expected_ids + finish_ids, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1084, in _filesync_read
    raise exceptions.AdbCommandFailureException('Command failed: {}'.format(reason))
adb_shell.exceptions.AdbCommandFailureException: Command failed: open failed: No such file or directory
INFO:root:ADB Push-Progress: /data/local/tmp/to_upload.tar.gz bytes_written:65536 total_bytes:2773139
INFO:root:ADB Push-Progress: /data/local/tmp/to_upload.tar.gz bytes_written:131072 total_bytes:2773139
...
JeffLIrion commented 3 years ago

Closed by https://github.com/JeffLIrion/adb_shell/pull/148