mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 11:51:14 +02:00
Merge pull request #13 from flatcar-linux/dongsu/retry-losetup
build_library: retry losetup up to 10 seconds
This commit is contained in:
commit
074a4a4498
@ -11,6 +11,7 @@ import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import uuid
|
||||
|
||||
# First sector we can use.
|
||||
@ -433,17 +434,23 @@ def FormatFat(part, device):
|
||||
def PartitionLoop(options, partition):
|
||||
"""Allocate (and automatically free) loop devices for a partition."""
|
||||
|
||||
loop_dev = subprocess.check_output(['sudo', 'losetup',
|
||||
'--offset', str(partition['first_byte']),
|
||||
'--sizelimit', str(partition['bytes']),
|
||||
'--find', '--show', options.disk_image])
|
||||
loop_dev = loop_dev.strip()
|
||||
attempts = 0
|
||||
|
||||
try:
|
||||
yield loop_dev
|
||||
finally:
|
||||
Sudo(['losetup', '--detach', loop_dev])
|
||||
while attempts < 10:
|
||||
try:
|
||||
loop_dev = subprocess.check_output(['sudo', 'losetup',
|
||||
'--offset', str(partition['first_byte']),
|
||||
'--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])
|
||||
|
||||
def FormatPartition(options, part):
|
||||
print "Formatting partition %s (%s) as %s" % (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user