mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +00:00
Use the pinned system compressor for Play payload preparation
This commit is contained in:
1 parent
567ca34a48
commit
d2298f4109
3 files changed
+20
-3
No files matched your search
@@ -2,13 +2,15 @@ import gzip
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import os
|
||||
from contextlib import ExitStack
|
||||
|
||||
|
||||
def prepare(source, destination, definition):
|
||||
if definition['method'] not in {'gzip-to-zstd-19', 'zstd-to-zstd-19'}:
|
||||
raise ValueError('Unsupported component preparation method')
|
||||
version = subprocess.check_output(['zstd', '--version'], text=True)
|
||||
zstd = os.environ.get('DROIDDECK_ZSTD', 'zstd')
|
||||
version = subprocess.check_output([zstd, '--version'], text=True)
|
||||
if 'v' + definition['zstd_version'] + ',' not in version:
|
||||
raise ValueError('Component preparation requires the pinned zstd version')
|
||||
digest = hashlib.sha256()
|
||||
@@ -18,12 +20,12 @@ def prepare(source, destination, definition):
|
||||
if definition['method'] == 'gzip-to-zstd-19':
|
||||
original = stack.enter_context(gzip.open(source, 'rb'))
|
||||
else:
|
||||
decoder = subprocess.Popen(['zstd', '-dc', str(source)], stdout=subprocess.PIPE)
|
||||
decoder = subprocess.Popen([zstd, '-dc', str(source)], stdout=subprocess.PIPE)
|
||||
stack.callback(decoder.wait)
|
||||
stack.callback(lambda: decoder.poll() is None and decoder.terminate())
|
||||
original = stack.enter_context(decoder.stdout)
|
||||
output = stack.enter_context(Path(destination).open('xb'))
|
||||
process = subprocess.Popen(['zstd', '-19', '-T4', '-c'], stdin=subprocess.PIPE, stdout=output)
|
||||
process = subprocess.Popen([zstd, '-19', '-T4', '-c'], stdin=subprocess.PIPE, stdout=output)
|
||||
try:
|
||||
for block in iter(lambda: original.read(1024 * 1024), b''):
|
||||
size += len(block)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import gzip
|
||||
import os
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import re
|
||||
@@ -6,6 +7,7 @@ import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from tools.playstore.prepare_archive import prepare
|
||||
|
||||
@@ -54,6 +56,16 @@ class PlayArchivePreparationTest(unittest.TestCase):
|
||||
prepare(original, output, definition)
|
||||
self.assertEqual(self.content, subprocess.check_output(['zstd', '-dc', str(output)]))
|
||||
|
||||
def test_pinned_executable_is_used_when_another_zstd_shadows_the_path(self):
|
||||
actual = shutil.which('zstd')
|
||||
directory = self.root / 'shadow'
|
||||
directory.mkdir()
|
||||
(directory / 'zstd').symlink_to(shutil.which('false'))
|
||||
output = self.root / 'prepared.tar.zst'
|
||||
with patch.dict(os.environ, DROIDDECK_ZSTD=actual, PATH=str(directory) + os.pathsep + os.environ['PATH']):
|
||||
prepare(self.source, output, self.definition)
|
||||
self.assertEqual(self.content, subprocess.check_output([actual, '-dc', str(output)]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user