Skip to content

Commit

Permalink
Bugfix: Checking if Android app bundle is signed got stuck (#36)
Browse files Browse the repository at this point in the history
* Add timeouts to reading from streams

* Add type annotation
  • Loading branch information
priitlatt authored Jun 2, 2020
1 parent dfdc556 commit 75a3999
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.2.1
-------------

**Improvements**

- Bugfix: Reading `jarsigner verify` output streams got stuck on some Android App bundles.

Version 0.2.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion src/codemagic/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "codemagic-cli-tools"
__description__ = "CLI tools used in Codemagic builds"
__version__ = "0.2.0"
__version__ = "0.2.1"
__url__ = 'https://github.com/codemagic-ci-cd/cli-tools'
__licence__ = 'GNU General Public License v3.0'
20 changes: 19 additions & 1 deletion src/codemagic/cli/cli_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import shlex
import subprocess
import sys
import threading
import time
import queue
from typing import IO
from typing import Optional
from typing import Sequence
Expand Down Expand Up @@ -54,7 +56,23 @@ def _log_exec_completed(self):
self.logger.debug(f'Completed "{self.safe_form}" with returncode {self.returncode} in {duration}')

def _handle_stream(self, input_stream: IO, output_stream: IO, buffer_size: Optional[int] = None) -> str:
chunk = (input_stream.read(buffer_size) if buffer_size else input_stream.read()).decode()
result: queue.Queue[bytes] = queue.Queue()

def read_result():
if buffer_size:
result.put(input_stream.read(buffer_size))
else:
result.put(input_stream.read())

stream_reader = threading.Thread(target=read_result)
stream_reader.start()
stream_reader.join(1) # Under normal circumstances reading the stream should never take full second

try:
chunk = result.get(block=False).decode()
except queue.Empty:
chunk = ''

if self._print_streams:
output_stream.write(chunk)
return chunk
Expand Down

0 comments on commit 75a3999

Please sign in to comment.