build_library: make a loop only for losetup in PartitionLoop

Fix a bug in PartitionLoop that ends up returning a false string,
which results in FormatPartition failing.
This commit is contained in:
Dongsu Park 2019-06-28 17:06:19 +02:00
parent 074a4a4498
commit a8cafdb31c

View File

@ -435,6 +435,7 @@ def PartitionLoop(options, partition):
"""Allocate (and automatically free) loop devices for a partition."""
attempts = 0
loop_dev = ''
while attempts < 10:
try:
@ -443,14 +444,14 @@ def PartitionLoop(options, partition):
'--sizelimit', str(partition['bytes']),
'--find', '--show', options.disk_image])
loop_dev = loop_dev.strip()
yield loop_dev
except:
attempts += 1
time.sleep(1)
finally:
Sudo(['losetup', '--detach', loop_dev])
try:
yield loop_dev
finally:
Sudo(['losetup', '--detach', loop_dev])
def FormatPartition(options, part):
print "Formatting partition %s (%s) as %s" % (