Fix source_parts usage

Addresses issue #221
This commit is contained in:
2Shirt 2023-08-26 14:30:22 -07:00
parent 460fd9c952
commit dbe4a342cc
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 15 additions and 7 deletions

View file

@ -244,7 +244,7 @@ class BlockPair():
# Functions
def add_clone_block_pairs(state) -> None:
def add_clone_block_pairs(state) -> list[hw_disk.Disk]:
"""Add device to device block pairs and set settings if necessary."""
source_sep = get_partition_separator(state.source.path.name)
dest_sep = get_partition_separator(state.destination.path.name)
@ -255,6 +255,7 @@ def add_clone_block_pairs(state) -> None:
# Add pairs from previous run
if settings['Partition Mapping']:
source_parts = []
for part_map in settings['Partition Mapping']:
bp_source = hw_disk.Disk(
f'{state.source.path}{source_sep}{part_map[0]}',
@ -262,8 +263,9 @@ def add_clone_block_pairs(state) -> None:
bp_dest = pathlib.Path(
f'{state.destination.path}{dest_sep}{part_map[1]}',
)
source_parts.append(bp_source)
state.add_block_pair(bp_source, bp_dest)
return
return source_parts
# Add pairs from selection
source_parts = menus.select_disk_parts('Clone', state.source)
@ -271,7 +273,7 @@ def add_clone_block_pairs(state) -> None:
# Whole disk (or single partition via args), skip settings
bp_dest = state.destination.path
state.add_block_pair(state.source, bp_dest)
return
return source_parts
# New run, use new settings file
settings['Needs Format'] = True
@ -306,13 +308,19 @@ def add_clone_block_pairs(state) -> None:
# Save settings
state.save_settings(settings)
# Done
return source_parts
def add_image_block_pairs(state) -> None:
def add_image_block_pairs(state) -> list[hw_disk.Disk]:
"""Add device to image file block pairs."""
source_parts = menus.select_disk_parts(state.mode, state.source)
for part in source_parts:
state.add_block_pair(part, state.destination)
# Done
return source_parts
def build_block_pair_report(block_pairs, settings) -> list:
"""Build block pair report, returns list."""
@ -378,7 +386,7 @@ def build_sfdisk_partition_line(table_type, dev_path, size, details) -> str:
# Set dest type
if re.match(r'^0x\w+$', source_type):
# Both source and dest are MBR
# Source is a MBR type
source_table_type = 'MBR'
if table_type == 'MBR':
dest_type = source_type.replace('0x', '').lower()

View file

@ -378,9 +378,9 @@ class State():
# Add block pairs
if self.mode == 'Clone':
add_clone_block_pairs(self)
source_parts = add_clone_block_pairs(self)
else:
add_image_block_pairs(self)
source_parts = add_image_block_pairs(self)
# Update SMART data
## TODO: Verify if needed