mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 06:01:41 +02:00
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:
parent
b6c6a05404
commit
ea0f478cfa
@ -198,7 +198,7 @@ def GetPartitionTableFromImage(options, config, partitions):
|
|||||||
"""
|
"""
|
||||||
block_size = config['metadata']['block_size']
|
block_size = config['metadata']['block_size']
|
||||||
cgpt_show = subprocess.check_output(
|
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'):
|
for line in cgpt_show.split('\n'):
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
@ -235,7 +235,7 @@ def GetPartitionTableFromImage(options, config, partitions):
|
|||||||
with PartitionLoop(options, part) as loop_dev:
|
with PartitionLoop(options, part) as loop_dev:
|
||||||
try:
|
try:
|
||||||
part['image_fs_type'] = subprocess.check_output(
|
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:
|
except subprocess.CalledProcessError:
|
||||||
part['image_fs_type'] = None
|
part['image_fs_type'] = None
|
||||||
|
|
||||||
@ -452,6 +452,7 @@ def PartitionLoop(options, partition):
|
|||||||
'--sizelimit', str(partition['bytes']),
|
'--sizelimit', str(partition['bytes']),
|
||||||
'--find', '--show', options.disk_image])
|
'--find', '--show', options.disk_image])
|
||||||
loop_dev = loop_dev.strip()
|
loop_dev = loop_dev.strip()
|
||||||
|
loop_dev = loop_dev.decode('utf8')
|
||||||
err = None
|
err = None
|
||||||
break
|
break
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
@ -785,7 +786,7 @@ def Verity(options):
|
|||||||
'--hash-block-size', part['fs_block_size'],
|
'--hash-block-size', part['fs_block_size'],
|
||||||
'--data-blocks', part['fs_blocks'],
|
'--data-blocks', part['fs_blocks'],
|
||||||
'--hash-offset', part['fs_bytes'],
|
'--hash-offset', part['fs_bytes'],
|
||||||
loop_dev, loop_dev])
|
loop_dev, loop_dev]).decode('utf8')
|
||||||
print(verityout.strip())
|
print(verityout.strip())
|
||||||
m = re.search("Root hash:\s+([a-f0-9]{64})$", verityout, re.IGNORECASE|re.MULTILINE)
|
m = re.search("Root hash:\s+([a-f0-9]{64})$", verityout, re.IGNORECASE|re.MULTILINE)
|
||||||
if not m:
|
if not m:
|
||||||
|
@ -128,6 +128,8 @@ def DepsToCopy(ldd_files, allow_list):
|
|||||||
|
|
||||||
if not stdout_data: continue
|
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,
|
logging.debug('ldd for %s = stdout = %s stderr =%s', file_name,
|
||||||
stdout_data, stderr_data)
|
stdout_data, stderr_data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user