Refactor set_partition_type() setting lp_partition earlier (#746204)
Refactor GParted_Core::set_partition_type(). 1) Set lp_partition variable earlier and use a single if lp_partition set condition, rather than in both if conditions for the normal file system case and the LVM2 Physical Volume case. 2) Stop calling Utils::get_filesystem_string() multiple times, instead save the result in a local variable. Tidies the code a little and reorders it in preparation for the following fix to only set the lvm partition flag when support, making that code change simpler. Bug 746204 - Creating partitions on pc98 table fails with lvm flag not available
This commit is contained in:
parent
9f6110ce4c
commit
c882666e3a
|
@ -3167,55 +3167,54 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
|
|||
PedDisk* lp_disk = NULL ;
|
||||
if ( get_device_and_disk( partition .device_path, lp_device, lp_disk ) )
|
||||
{
|
||||
//Lookup libparted file system type using GParted's name, as most match
|
||||
PedFileSystemType * fs_type =
|
||||
ped_file_system_type_get( Utils::get_filesystem_string( partition .filesystem ) .c_str() ) ;
|
||||
|
||||
//If not found, and FS is linux-swap, then try linux-swap(v1)
|
||||
if ( ! fs_type && Utils::get_filesystem_string( partition .filesystem ) == "linux-swap" )
|
||||
fs_type = ped_file_system_type_get( "linux-swap(v1)" ) ;
|
||||
|
||||
//If not found, and FS is linux-swap, then try linux-swap(new)
|
||||
if ( ! fs_type && Utils::get_filesystem_string( partition .filesystem ) == "linux-swap" )
|
||||
fs_type = ped_file_system_type_get( "linux-swap(new)" ) ;
|
||||
|
||||
//default is Linux (83)
|
||||
if ( ! fs_type )
|
||||
fs_type = ped_file_system_type_get( "ext2" ) ;
|
||||
|
||||
if ( fs_type && partition .filesystem != FS_LVM2_PV )
|
||||
PedPartition* lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition.get_sector() );
|
||||
if ( lp_partition )
|
||||
{
|
||||
PedPartition* lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
|
||||
Glib::ustring fs_type = Utils::get_filesystem_string( partition.filesystem );
|
||||
|
||||
//Also clear any libparted LVM flag so that it doesn't override the file system type
|
||||
if ( lp_partition &&
|
||||
ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 0 ) &&
|
||||
ped_partition_set_system( lp_partition, fs_type ) &&
|
||||
commit( lp_disk ) )
|
||||
// Lookup libparted file system type using GParted's name, as most match
|
||||
PedFileSystemType * lp_fs_type = ped_file_system_type_get( fs_type.c_str() );
|
||||
|
||||
// If not found, and FS is linux-swap, then try linux-swap(v1)
|
||||
if ( ! lp_fs_type && fs_type == "linux-swap" )
|
||||
lp_fs_type = ped_file_system_type_get( "linux-swap(v1)" );
|
||||
|
||||
// If not found, and FS is linux-swap, then try linux-swap(new)
|
||||
if ( ! lp_fs_type && fs_type == "linux-swap" )
|
||||
lp_fs_type = ped_file_system_type_get( "linux-swap(new)" );
|
||||
|
||||
// default is Linux (83)
|
||||
if ( ! lp_fs_type )
|
||||
lp_fs_type = ped_file_system_type_get( "ext2" );
|
||||
|
||||
if ( lp_fs_type && partition.filesystem != FS_LVM2_PV )
|
||||
{
|
||||
operationdetail .get_last_child() .add_child(
|
||||
OperationDetail( String::ucompose( _("new partition type: %1"),
|
||||
lp_partition ->fs_type ->name ),
|
||||
STATUS_NONE,
|
||||
FONT_ITALIC ) ) ;
|
||||
|
||||
return_value = true ;
|
||||
// Also clear any libparted LVM flag so that it doesn't
|
||||
// override the file system type
|
||||
if ( ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 0 ) &&
|
||||
ped_partition_set_system( lp_partition, lp_fs_type ) &&
|
||||
commit( lp_disk ) )
|
||||
{
|
||||
operationdetail.get_last_child().add_child(
|
||||
OperationDetail( String::ucompose( _("new partition type: %1"),
|
||||
lp_partition->fs_type->name ),
|
||||
STATUS_NONE,
|
||||
FONT_ITALIC ) );
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( partition .filesystem == FS_LVM2_PV )
|
||||
{
|
||||
PedPartition* lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
|
||||
|
||||
if ( lp_partition &&
|
||||
ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 1 ) &&
|
||||
commit( lp_disk ) )
|
||||
else if ( partition.filesystem == FS_LVM2_PV )
|
||||
{
|
||||
operationdetail .get_last_child() .add_child(
|
||||
OperationDetail( String::ucompose( _("new partition flag: %1"),
|
||||
ped_partition_flag_get_name( PED_PARTITION_LVM ) ),
|
||||
STATUS_NONE,
|
||||
FONT_ITALIC ) ) ;
|
||||
return_value = true ;
|
||||
if ( ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 1 ) &&
|
||||
commit( lp_disk ) )
|
||||
{
|
||||
operationdetail.get_last_child().add_child(
|
||||
OperationDetail( String::ucompose( _("new partition flag: %1"),
|
||||
ped_partition_flag_get_name( PED_PARTITION_LVM ) ),
|
||||
STATUS_NONE,
|
||||
FONT_ITALIC ) );
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue