Add option to mount all volumes for a specific dev

This commit is contained in:
2Shirt 2018-09-29 14:31:16 -06:00
parent 0fae4128ed
commit 162712871e
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -153,7 +153,7 @@ def cleanup_transfer(dest_path):
except Exception:
pass
def find_core_storage_volumes():
def find_core_storage_volumes(device_path=None):
"""Try to create block devices for any Apple CoreStorage volumes."""
corestorage_uuid = '53746f72-6167-11aa-aa11-00306543ecac'
dmsetup_cmd_file = '{TmpDir}/dmsetup_command'.format(**global_vars)
@ -162,6 +162,8 @@ def find_core_storage_volumes():
cmd = [
'lsblk', '--json', '--list', '--paths',
'--output', 'NAME,PARTTYPE']
if device:
cmd.append(device_path)
result = run_program(cmd)
json_data = json.loads(result.stdout.decode())
devs = json_data.get('blockdevices', [])
@ -257,9 +259,9 @@ def mount_volumes(all_devices=True, device_path=None, read_write=False):
if not all_devices and device_path:
# Only mount volumes for specific device
cmd.append(device_path)
else:
# Check for Apple CoreStorage volumes first
find_core_storage_volumes()
# Check for Apple CoreStorage volumes first
find_core_storage_volumes(device_path)
# Get list of block devices
result = run_program(cmd)
@ -269,8 +271,11 @@ def mount_volumes(all_devices=True, device_path=None, read_write=False):
# Get list of volumes
volumes = {}
for dev in devs:
if not dev.get('children', []):
volumes.update({dev['name']: dev})
for child in dev.get('children', []):
volumes.update({child['name']: child})
if not child.get('children', []):
volumes.update({child['name']: child})
for grandchild in child.get('children', []):
volumes.update({grandchild['name']: grandchild})