From a8cafdb31cda569271f76a0759cc4aafb53ea13e Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Fri, 28 Jun 2019 17:06:19 +0200 Subject: [PATCH] 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. --- build_library/disk_util | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build_library/disk_util b/build_library/disk_util index 9a54ed0774..7fd180b23f 100755 --- a/build_library/disk_util +++ b/build_library/disk_util @@ -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" % (