Skip to content

Commit acac626

Browse files
Don't hardcode losetup device
1 parent 8883c2a commit acac626

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,4 @@
7676

7777
CHROMEOS_BLOCK_SIZE = 512
7878

79-
LOOP_DEV = '/dev/loop1'
80-
8179
HLS_MINIMUM_IA_VERSION = '2.0.10'

lib/inputstreamhelper.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def __init__(self, protocol, drm=None):
2525

2626
self._url = None
2727
self._download_path = None
28+
self._loop_dev = None
29+
self._attached_loop_dev = False
2830
self._mounted = False
29-
self._loop_dev = False
3031

3132
self.protocol = protocol
3233
self.drm = drm
@@ -136,16 +137,23 @@ def _parse_chromeos_offset(self, bin_path):
136137
self._log('Failed to calculate losetup offset.')
137138
return False
138139

140+
def _set_loop_dev(self):
141+
"""Set an unused loop device that's available for use."""
142+
cmd = ['losetup', '-f']
143+
self._loop_dev = subprocess.check_output(cmd).strip()
144+
self._log('Found free loop device: {0}'.format(self._loop_dev))
145+
return True
146+
139147
def _losetup(self, bin_path):
140148
"""Setup Chrome OS loop device."""
141-
cmd = ['losetup', config.LOOP_DEV, bin_path, '-o', self._parse_chromeos_offset(bin_path)]
149+
cmd = ['losetup', self._loop_dev, bin_path, '-o', self._parse_chromeos_offset(bin_path)]
142150
subprocess.check_output(cmd)
143-
self._loop_dev = True
151+
self._attached_loop_dev = True
144152
return True
145153

146154
def _mnt_loop_dev(self):
147155
"""Mount loop device to self._mnt_path()"""
148-
cmd = ['mount', '-t', 'ext2', config.LOOP_DEV, '-o', 'ro', self._mnt_path()]
156+
cmd = ['mount', '-t', 'ext2', self._loop_dev, '-o', 'ro', self._mnt_path()]
149157
subprocess.check_output(cmd)
150158
self._mounted = True
151159
return True
@@ -321,10 +329,10 @@ def _install_widevine_cdm_x86(self):
321329
self._unzip(self._cdm_path())
322330
if self._widevine_eula():
323331
self._install_cdm()
332+
self._cleanup()
324333
else:
325334
self._cleanup()
326335
return False
327-
self._cleanup()
328336

329337
if self._has_widevine_cdm():
330338
dialog.ok(self._language(30001), self._language(30003))
@@ -367,10 +375,9 @@ def _install_widevine_cdm_arm(self):
367375

368376
bin_filename = self._url.split('/')[-1].replace('.zip', '')
369377
bin_path = os.path.join(self._temp_path(), bin_filename)
370-
if not self._unzip(self._temp_path(), bin_filename) or not self._losetup(bin_path) or not self._mnt_loop_dev():
378+
if not self._unzip(self._temp_path(), bin_filename) or not self._set_loop_dev() or not self._losetup(bin_path) or not self._mnt_loop_dev():
371379
self._cleanup()
372380
busy_dialog.close()
373-
return False
374381
else:
375382
self._extract_cdm_from_img()
376383
self._install_cdm()
@@ -447,8 +454,8 @@ def _cleanup(self):
447454
cmd = ['umount', self._mnt_path()]
448455
subprocess.check_call(cmd)
449456
self._mounted = False
450-
if self._loop_dev:
451-
cmd = ['losetup', '-d', config.LOOP_DEV]
457+
if self._attached_loop_dev:
458+
cmd = ['losetup', '-d', self._loop_dev]
452459
subprocess.check_call(cmd)
453460
self._loop_dev = False
454461

0 commit comments

Comments
 (0)