@@ -25,8 +25,9 @@ def __init__(self, protocol, drm=None):
25
25
26
26
self ._url = None
27
27
self ._download_path = None
28
+ self ._loop_dev = None
29
+ self ._attached_loop_dev = False
28
30
self ._mounted = False
29
- self ._loop_dev = False
30
31
31
32
self .protocol = protocol
32
33
self .drm = drm
@@ -136,16 +137,23 @@ def _parse_chromeos_offset(self, bin_path):
136
137
self ._log ('Failed to calculate losetup offset.' )
137
138
return False
138
139
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
+
139
147
def _losetup (self , bin_path ):
140
148
"""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 )]
142
150
subprocess .check_output (cmd )
143
- self ._loop_dev = True
151
+ self ._attached_loop_dev = True
144
152
return True
145
153
146
154
def _mnt_loop_dev (self ):
147
155
"""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 ()]
149
157
subprocess .check_output (cmd )
150
158
self ._mounted = True
151
159
return True
@@ -321,10 +329,10 @@ def _install_widevine_cdm_x86(self):
321
329
self ._unzip (self ._cdm_path ())
322
330
if self ._widevine_eula ():
323
331
self ._install_cdm ()
332
+ self ._cleanup ()
324
333
else :
325
334
self ._cleanup ()
326
335
return False
327
- self ._cleanup ()
328
336
329
337
if self ._has_widevine_cdm ():
330
338
dialog .ok (self ._language (30001 ), self ._language (30003 ))
@@ -367,10 +375,9 @@ def _install_widevine_cdm_arm(self):
367
375
368
376
bin_filename = self ._url .split ('/' )[- 1 ].replace ('.zip' , '' )
369
377
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 ():
371
379
self ._cleanup ()
372
380
busy_dialog .close ()
373
- return False
374
381
else :
375
382
self ._extract_cdm_from_img ()
376
383
self ._install_cdm ()
@@ -447,8 +454,8 @@ def _cleanup(self):
447
454
cmd = ['umount' , self ._mnt_path ()]
448
455
subprocess .check_call (cmd )
449
456
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 ]
452
459
subprocess .check_call (cmd )
453
460
self ._loop_dev = False
454
461
0 commit comments