Commit 6c601a08 authored by Jérome Perrin's avatar Jérome Perrin

prune: fix some UnicodeDecodeError on python3 with binary scripts

Some softwares have some binary executables in builout bin folder,
reading them as text can fail. In this case we can ignore them.
parent affcc2d9
Pipeline #9592 passed with stage
......@@ -217,7 +217,10 @@ def getUsageSignatureFromSoftwareAndSharedPart(
signatures[installed_cfg] = f.read()
for script in glob.glob(os.path.join(software_root, '*', 'bin', '*')):
with open(script) as f:
signatures[script] = f.read()
try:
signatures[script] = f.read()
except UnicodeDecodeError:
logger.debug("Skipping script %s that could not be decoded", script)
if shared_root:
for shared_signature in glob.glob(os.path.join(shared_root, '*', '*',
'.*signature')):
......
......@@ -31,6 +31,7 @@ import os
import shutil
import unittest
import slapos.client
import six
try:
import mock
......@@ -139,11 +140,19 @@ class TestPrune(unittest.TestCase):
script = os.path.join(fake_software_path, 'bin', 'buildout')
with open(script, 'w') as f:
f.write('#!{}'.format(used_in_script))
# bin/ can also contain binary executables, this should not cause problems
binary_script = os.path.join(fake_software_path, 'bin', 'binary')
with open(binary_script, 'wb') as f:
f.write(b'\x80')
do_prune(self.logger, self.config, False)
self.assertTrue(os.path.exists(used_in_script))
self.assertFalse(os.path.exists(not_used))
self.logger.warning.assert_called_with(
'Unusued shared parts at %s%s', not_used, ' ... removed')
if six.PY3:
self.logger.debug.assert_any_call(
'Skipping script %s that could not be decoded', binary_script)
def test_shared_part_used_in_recursive_instance(self):
used_in_software_from_instance = self._createSharedPart('used_in_software_from_instance')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment