build_library: Fix some string vs bytes issues

This is some fallout from converting scripts from python2 to
python3. Output received from the functions in subprocess module now
return bytearrays, but we operate on them as if they were a text. So
decode the bytearrays to strings. Otherwise we are either getting some
junk values passed to the command line utilities (for example:
`b'/dev/loop2'` instead of `/dev/loop2`), or exceptions are thrown,
because a function expected a string.
This commit is contained in:
Krzesimir Nowak 2021-08-17 11:33:07 +02:00
parent b6c6a05404
commit ea0f478cfa
2 changed files with 6 additions and 3 deletions

View File

@ -198,7 +198,7 @@ def GetPartitionTableFromImage(options, config, partitions):
"""
block_size = config['metadata']['block_size']
cgpt_show = subprocess.check_output(
['cgpt', 'show', '-q', options.disk_image])
['cgpt', 'show', '-q', options.disk_image]).decode('utf8')
for line in cgpt_show.split('\n'):
if not line.strip():
continue
@ -235,7 +235,7 @@ def GetPartitionTableFromImage(options, config, partitions):
with PartitionLoop(options, part) as loop_dev:
try:
part['image_fs_type'] = subprocess.check_output(
['sudo', 'blkid', '-o', 'value', '-s', 'TYPE', loop_dev]).strip()
['sudo', 'blkid', '-o', 'value', '-s', 'TYPE', loop_dev]).strip().decode('utf8')
except subprocess.CalledProcessError:
part['image_fs_type'] = None
@ -452,6 +452,7 @@ def PartitionLoop(options, partition):
'--sizelimit', str(partition['bytes']),
'--find', '--show', options.disk_image])
loop_dev = loop_dev.strip()
loop_dev = loop_dev.decode('utf8')
err = None
break
except subprocess.CalledProcessError as error:
@ -785,7 +786,7 @@ def Verity(options):
'--hash-block-size', part['fs_block_size'],
'--data-blocks', part['fs_blocks'],
'--hash-offset', part['fs_bytes'],
loop_dev, loop_dev])
loop_dev, loop_dev]).decode('utf8')
print(verityout.strip())
m = re.search("Root hash:\s+([a-f0-9]{64})$", verityout, re.IGNORECASE|re.MULTILINE)
if not m:

View File

@ -128,6 +128,8 @@ def DepsToCopy(ldd_files, allow_list):
if not stdout_data: continue
stdout_data = stdout_data.decode('utf8')
stderr_data = stderr_data.decode('utf8')
logging.debug('ldd for %s = stdout = %s stderr =%s', file_name,
stdout_data, stderr_data)