Use pointers to Partitions in Operation classes (#759726)

Operation classes now internally use pointers to Partition objects and
take on management of their lifetimes.  As before, with the
PartitionVector class, when storing pointers in a class the Big 3 of
destructor, copy constructor and copy assignment operator also have to
be considered.

First, all the Partition objects are allocated in the derived Operation*
class parameterised constructors and freed in the associated
destructors.  However the Operation classes are never copy constructed
or copy assigned; they are only ever created and destroyed.  Only
pointers to the derived Operations are copied into the vector of pending
operations.  Therefore the copy construtor and copy assignment operator
aren't needed.  To enforce this provide inaccessible private
declarations without any implementation so that the compiler will
enforce this [1][2].

This example code fragment:
 1  OperationCheck o1( device, partition );
 2  OperationCheck o2 = o1;
 3  o2 = o1;
Does these OperationCheck calls:
 1  Implemented parameterised construtor,
 2  Disallowed copy constructor,
 3  Disallowed copy assignment

Trying to compile the above code would fail with errors like these:
    ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()':
    ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private
      OperationCheck( const OperationCheck & src );              // Not implemented copy constructor
      ^
    test.cc:2:21: error: within this context
      OperationCheck o2 = o1;
                          ^

    ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private
      OperationCheck & operator=( const OperationCheck & rhs );  // Not implemented copy assignment operator
                       ^
    test.cc:3:4: error: within this context
      o2 = o1;
         ^

[1] Disable copy constructor
    http://stackoverflow.com/questions/6077143/disable-copy-constructor
[2] Disable compiler-generated copy-assignment operator [duplicate]
    http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator

Bug 759726 - Implement Partition object polymorphism
This commit is contained in:
Mike Fleetwood 2015-09-20 10:50:57 +01:00 committed by Curtis Gedak
parent 6fd37c0745
commit b516b1093c
20 changed files with 363 additions and 125 deletions

View file

@ -45,10 +45,10 @@ public:
Operation() ;
virtual ~Operation() {}
Partition & get_partition_original() { return partition_original; };
const Partition & get_partition_original() const { return partition_original; };
virtual Partition & get_partition_new() { return partition_new; };
const virtual Partition & get_partition_new() const { return partition_new; };
Partition & get_partition_original();
const Partition & get_partition_original() const;
virtual Partition & get_partition_new();
const virtual Partition & get_partition_new() const;
virtual void apply_to_visual( PartitionVector & partitions ) = 0;
virtual void create_description() = 0 ;
@ -72,8 +72,20 @@ protected:
void substitute_new( PartitionVector & partitions );
void insert_new( PartitionVector & partitions );
Partition partition_original;
Partition partition_new;
Partition * partition_original;
Partition * partition_new;
private:
// Disable compiler generated copy constructor and copy assignment operator by
// providing private declarations and no definition. Code which tries to copy
// construct or copy assign this class will fail to compile.
// References:
// * Disable copy constructor
// http://stackoverflow.com/questions/6077143/disable-copy-constructor
// * Disable compiler-generated copy-assignment operator [duplicate]
// http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator
Operation( const Operation & src ); // Not implemented copy constructor
Operation & operator=( const Operation & rhs ); // Not implemented copy assignment operator
};
} //GParted

View file

@ -31,10 +31,14 @@ public:
, const Partition & partition_orig
, const Partition & partition_new
) ;
~OperationChangeUUID();
void apply_to_visual( PartitionVector & partitions );
private:
OperationChangeUUID( const OperationChangeUUID & src ); // Not implemented copy constructor
OperationChangeUUID & operator=( const OperationChangeUUID & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );
} ;

View file

@ -28,10 +28,14 @@ class OperationCheck : public Operation
{
public:
OperationCheck( const Device & device, const Partition & partition ) ;
~OperationCheck();
void apply_to_visual( PartitionVector & partitions );
private:
OperationCheck( const OperationCheck & src ); // Not implemented copy constructor
OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator
Partition & get_partition_new();
const Partition & get_partition_new() const;

View file

@ -31,17 +31,21 @@ public:
const Partition & partition_orig,
const Partition & partition_new,
const Partition & partition_copied ) ;
~OperationCopy();
Partition & get_partition_copied() { return partition_copied; };
const Partition & get_partition_copied() const { return partition_copied; };
Partition & get_partition_copied();
const Partition & get_partition_copied() const;
void apply_to_visual( PartitionVector & partitions );
private:
OperationCopy( const OperationCopy & src ); // Not implemented copy constructor
OperationCopy & operator=( const OperationCopy & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );
Partition partition_copied;
Partition * partition_copied;
};
} //GParted

View file

@ -30,10 +30,14 @@ public:
OperationCreate( const Device & device,
const Partition & partition_orig,
const Partition & partition_new ) ;
~OperationCreate();
void apply_to_visual( PartitionVector & partitions );
private:
OperationCreate( const OperationCreate & src ); // Not implemented copy constructor
OperationCreate & operator=( const OperationCreate & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );
} ;

View file

@ -28,10 +28,14 @@ class OperationDelete : public Operation
{
public:
OperationDelete( const Device & device, const Partition & partition_orig ) ;
~OperationDelete();
void apply_to_visual( PartitionVector & partitions );
private:
OperationDelete( const OperationDelete & src ); // Not implemented copy constructor
OperationDelete & operator=( const OperationDelete & rhs ); // Not implemented copy assignment operator
Partition & get_partition_new();
const Partition & get_partition_new() const;

View file

@ -30,10 +30,14 @@ public:
OperationFormat( const Device & device,
const Partition & partition_orig,
const Partition & partition_new ) ;
~OperationFormat();
void apply_to_visual( PartitionVector & partitions );
private:
OperationFormat( const OperationFormat & src ); // Not implemented copy constructor
OperationFormat & operator=( const OperationFormat & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );
} ;

View file

@ -30,10 +30,14 @@ public:
OperationLabelFileSystem( const Device & device,
const Partition & partition_orig,
const Partition & partition_new );
~OperationLabelFileSystem();
void apply_to_visual( PartitionVector & partitions );
private:
OperationLabelFileSystem( const OperationLabelFileSystem & src ); // Not implemented copy constructor
OperationLabelFileSystem & operator=( const OperationLabelFileSystem & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );
} ;

View file

@ -30,10 +30,14 @@ public:
OperationNamePartition( const Device & device,
const Partition & partition_orig,
const Partition & partition_new );
~OperationNamePartition();
void apply_to_visual( PartitionVector & partitions );
private:
OperationNamePartition( const OperationNamePartition & src ); // Not implemented copy constructor
OperationNamePartition & operator=( const OperationNamePartition & rhs ); // Not implemented copy assignment operator
void create_description();
bool merge_operations( const Operation & candidate );
};

View file

@ -30,10 +30,14 @@ public:
OperationResizeMove( const Device & device,
const Partition & partition_orig,
const Partition & partition_new ) ;
~OperationResizeMove();
void apply_to_visual( PartitionVector & partitions );
private:
OperationResizeMove( const OperationResizeMove & src ); // Not implemented copy constructor
OperationResizeMove & operator=( const OperationResizeMove & rhs ); // Not implemented copy assignment operator
void create_description() ;
bool merge_operations( const Operation & candidate );

View file

@ -27,11 +27,41 @@ Operation::Operation()
{
}
Partition & Operation::get_partition_original()
{
g_assert( partition_original != NULL ); // Bug: Not initialised by derived Operation*() constructor or reset later
return *partition_original;
}
const Partition & Operation::get_partition_original() const
{
g_assert( partition_original != NULL ); // Bug: Not initialised by derived Operation*() constructor or reset later
return *partition_original;
}
Partition & Operation::get_partition_new()
{
g_assert( partition_new != NULL ); // Bug: Not initialised by derived Operation*() constructor or reset later
return *partition_new;
}
const Partition & Operation::get_partition_new() const
{
g_assert( partition_new != NULL ); // Bug: Not initialised by derived Operation*() constructor or reset later
return *partition_new;
}
int Operation::find_index_original( const PartitionVector & partitions )
{
g_assert( partition_original != NULL ); // Bug: Not initialised by derived Operation*() constructor or reset later
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
if ( partition_original .sector_start >= partitions[ t ] .sector_start &&
partition_original .sector_end <= partitions[ t ] .sector_end )
if ( partition_original->sector_start >= partitions[t].sector_start &&
partition_original->sector_end <= partitions[t].sector_end )
return t ;
return -1 ;
@ -41,9 +71,11 @@ int Operation::find_index_original( const PartitionVector & partitions )
// this->partition_new. Return vector index or -1 when no match found.
int Operation::find_index_new( const PartitionVector & partitions )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
for ( unsigned int i = 0 ; i < partitions.size() ; i ++ )
if ( partition_new.sector_start >= partitions[i].sector_start &&
partition_new.sector_end <= partitions[i].sector_end )
if ( partition_new->sector_start >= partitions[i].sector_start &&
partition_new->sector_end <= partitions[i].sector_end )
return i;
return -1;
@ -70,24 +102,27 @@ void Operation::insert_unallocated( PartitionVector & partitions,
// it with this operation's new partition.
void Operation::substitute_new( PartitionVector & partitions )
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
int index_extended;
int index;
if ( partition_original.inside_extended )
if ( partition_original->inside_extended )
{
index_extended = find_index_extended( partitions );
if ( index_extended >= 0 )
{
index = find_index_original( partitions[index_extended].logicals );
if ( index >= 0 )
partitions[index_extended].logicals[index] = partition_new;
partitions[index_extended].logicals[index] = *partition_new;
}
}
else
{
index = find_index_original( partitions );
if ( index >= 0 )
partitions[index] = partition_new;
partitions[index] = *partition_new;
}
}
@ -103,10 +138,13 @@ void Operation::insert_new( PartitionVector & partitions )
// on disk. Therefore they match the original partition when visually re-applying
// their operations to the disk graphic. Hence their use of,
// find_index_original().
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
int index_extended;
int index;
if ( partition_new.inside_extended )
if ( partition_new->inside_extended )
{
index_extended = find_index_extended( partitions );
if ( index_extended >= 0 )
@ -114,7 +152,7 @@ void Operation::insert_new( PartitionVector & partitions )
index = find_index_new( partitions[index_extended].logicals );
if ( index >= 0 )
{
partitions[index_extended].logicals[index] = partition_new;
partitions[index_extended].logicals[index] = *partition_new;
insert_unallocated( partitions[index_extended].logicals,
partitions[index_extended].sector_start,
@ -129,7 +167,7 @@ void Operation::insert_new( PartitionVector & partitions )
index = find_index_new( partitions );
if ( index >= 0 )
{
partitions[index] = partition_new;
partitions[index] = *partition_new;
insert_unallocated( partitions, 0, device.length-1, device.sector_size, false );
}

View file

@ -29,8 +29,16 @@ OperationChangeUUID::OperationChangeUUID( const Device & device
type = OPERATION_CHANGE_UUID ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationChangeUUID::~OperationChangeUUID()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationChangeUUID::apply_to_visual( PartitionVector & partitions )
@ -40,30 +48,35 @@ void OperationChangeUUID::apply_to_visual( PartitionVector & partitions )
void OperationChangeUUID::create_description()
{
if ( partition_new .uuid == UUID_RANDOM_NTFS_HALF ) {
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_new->uuid == UUID_RANDOM_NTFS_HALF )
{
/*TO TRANSLATORS: looks like Set half the UUID to a new random value on ntfs file system on /dev/sda1 */
description = String::ucompose( _("Set half the UUID to a new random value on %1 file system on %2")
, Utils::get_filesystem_string( partition_new .filesystem )
, partition_new .get_path()
) ;
} else {
description = String::ucompose( _("Set half the UUID to a new random value on %1 file system on %2"),
Utils::get_filesystem_string( partition_new->filesystem ),
partition_new->get_path() );
}
else
{
/*TO TRANSLATORS: looks like Set a new random UUID on ext4 file system on /dev/sda1 */
description = String::ucompose( _("Set a new random UUID on %1 file system on %2")
, Utils::get_filesystem_string( partition_new .filesystem )
, partition_new .get_path()
) ;
description = String::ucompose( _("Set a new random UUID on %1 file system on %2"),
Utils::get_filesystem_string( partition_new->filesystem ),
partition_new->get_path() );
}
}
bool OperationChangeUUID::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_CHANGE_UUID &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
// Changing half the UUID must not override changing all of it
if ( candidate.get_partition_new().uuid != UUID_RANDOM_NTFS_HALF )
{
partition_new.uuid = candidate.get_partition_new().uuid;
partition_new->uuid = candidate.get_partition_new().uuid;
create_description();
}
// Else no change required to this operation to merge candidate

View file

@ -26,7 +26,13 @@ OperationCheck::OperationCheck( const Device & device, const Partition & partiti
type = OPERATION_CHECK ;
this->device = device.get_copy_without_partitions();
partition_original = partition ;
this->partition_original = new Partition( partition );
}
OperationCheck::~OperationCheck()
{
delete partition_original;
partition_original = NULL;
}
Partition & OperationCheck::get_partition_new()
@ -34,7 +40,7 @@ Partition & OperationCheck::get_partition_new()
g_assert( false ); // Bug: OperationCheck class doesn't use partition_new
// Not reached. Return value to keep compiler quiet.
return partition_new;
return *partition_new;
}
const Partition & OperationCheck::get_partition_new() const
@ -42,7 +48,7 @@ const Partition & OperationCheck::get_partition_new() const
g_assert( false ); // Bug: OperationCheck class doesn't use partition_new
// Not reached. Return value to keep compiler quiet.
return partition_new;
return *partition_new;
}
void OperationCheck::apply_to_visual( PartitionVector & partitions )
@ -51,16 +57,20 @@ void OperationCheck::apply_to_visual( PartitionVector & partitions )
void OperationCheck::create_description()
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
/*TO TRANSLATORS: looks like Check and repair file system (ext3) on /dev/hda4 */
description = String::ucompose( _("Check and repair file system (%1) on %2"),
Utils::get_filesystem_string( partition_original .filesystem ),
partition_original .get_path() ) ;
Utils::get_filesystem_string( partition_original->filesystem ),
partition_original->get_path() );
}
bool OperationCheck::merge_operations( const Operation & candidate )
{
if ( candidate.type == OPERATION_CHECK &&
partition_original == candidate.get_partition_original() )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_CHECK &&
*partition_original == candidate.get_partition_original() )
// No steps required to merge this operation
return true;

View file

@ -30,17 +30,43 @@ OperationCopy::OperationCopy( const Device & device,
type = OPERATION_COPY ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this ->partition_copied = partition_copied ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
this->partition_copied = new Partition( partition_copied );
this ->partition_new .add_path(
String::ucompose( _("copy of %1"), this ->partition_copied .get_path() ), true ) ;
this->partition_new->add_path(
String::ucompose( _("copy of %1"), this->partition_copied->get_path() ), true );
}
OperationCopy::~OperationCopy()
{
delete partition_original;
delete partition_new;
delete partition_copied;
partition_original = NULL;
partition_new = NULL;
partition_copied = NULL;
}
Partition & OperationCopy::get_partition_copied()
{
g_assert( partition_copied != NULL ); // Bug: Not initialised by constructor or reset later
return *partition_copied;
}
const Partition & OperationCopy::get_partition_copied() const
{
g_assert( partition_copied != NULL ); // Bug: Not initialised by constructor or reset later
return *partition_copied;
}
void OperationCopy::apply_to_visual( PartitionVector & partitions )
{
if ( partition_original.type == TYPE_UNALLOCATED )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_original->type == TYPE_UNALLOCATED )
// Paste into unallocated space creating new partition
insert_new( partitions );
else
@ -50,20 +76,25 @@ void OperationCopy::apply_to_visual( PartitionVector & partitions )
void OperationCopy::create_description()
{
if ( partition_original .type == GParted::TYPE_UNALLOCATED )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_copied != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_original->type == TYPE_UNALLOCATED )
{
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 250 MiB) */
description = String::ucompose( _("Copy %1 to %2 (start at %3)"),
partition_copied .get_path(),
device .get_path(),
Utils::format_size( partition_new .sector_start, partition_new .sector_size ) ) ;
partition_copied->get_path(),
device.get_path(),
Utils::format_size( partition_new->sector_start,
partition_new->sector_size ) );
}
else
{
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd1 */
description = String::ucompose( _("Copy %1 to %2"),
partition_copied .get_path(),
partition_original .get_path() ) ;
partition_copied->get_path(),
partition_original->get_path() );
}
}

View file

@ -31,8 +31,16 @@ OperationCreate::OperationCreate( const Device & device,
type = OPERATION_CREATE ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationCreate::~OperationCreate()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationCreate::apply_to_visual( PartitionVector & partitions )
@ -42,7 +50,9 @@ void OperationCreate::apply_to_visual( PartitionVector & partitions )
void OperationCreate::create_description()
{
switch( partition_new .type )
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
switch( partition_new->type )
{
case GParted::TYPE_PRIMARY :
description = _("Primary Partition");
@ -59,32 +69,37 @@ void OperationCreate::create_description()
}
/*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 345 MiB) on /dev/hda */
description = String::ucompose( _("Create %1 #%2 (%3, %4) on %5"),
description,
partition_new .partition_number,
Utils::get_filesystem_string( partition_new .filesystem ),
Utils::format_size( partition_new .get_sector_length(), partition_new .sector_size ),
device .get_path() ) ;
description,
partition_new->partition_number,
Utils::get_filesystem_string( partition_new->filesystem ),
Utils::format_size( partition_new->get_sector_length(),
partition_new->sector_size ),
device.get_path() );
}
bool OperationCreate::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_FORMAT &&
candidate.get_partition_original().status == STAT_NEW &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
// Merge a format operation on a not yet created partition with the
// earlier operation which will create it.
partition_new = candidate.get_partition_new();
delete partition_new;
partition_new = new Partition( candidate.get_partition_new() );
create_description();
return true;
}
else if ( candidate.type == OPERATION_RESIZE_MOVE &&
candidate.get_partition_original().status == STAT_NEW &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
// Merge a resize/move operation on a not yet created partition with the
// earlier operation which will create it.
partition_new = candidate.get_partition_new();
delete partition_new;
partition_new = new Partition( candidate.get_partition_new() );
create_description();
return true;
}

View file

@ -27,7 +27,13 @@ OperationDelete::OperationDelete( const Device & device, const Partition & parti
type = OPERATION_DELETE ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this->partition_original = new Partition( partition_orig );
}
OperationDelete::~OperationDelete()
{
delete partition_original;
partition_original = NULL;
}
Partition & OperationDelete::get_partition_new()
@ -35,7 +41,7 @@ Partition & OperationDelete::get_partition_new()
g_assert( false ); // Bug: OperationDelete class doesn't use partition_new
// Not reached. Return value to keep compiler quiet.
return partition_new;
return *partition_new;
}
const Partition & OperationDelete::get_partition_new() const
@ -43,15 +49,17 @@ const Partition & OperationDelete::get_partition_new() const
g_assert( false ); // Bug: OperationDelete class doesn't use partition_new
// Not reached. Return value to keep compiler quiet.
return partition_new;
return *partition_new;
}
void OperationDelete::apply_to_visual( PartitionVector & partitions )
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
int index_extended;
int index;
if ( partition_original .inside_extended )
if ( partition_original->inside_extended )
{
index_extended = find_index_extended( partitions ) ;
@ -72,10 +80,10 @@ void OperationDelete::apply_to_visual( PartitionVector & partitions )
// If deleted partition was logical we have to decrease
// the partition numbers of the logicals with higher
// numbers by one (only if its a real partition)
if ( partition_original.status != STAT_NEW )
if ( partition_original->status != STAT_NEW )
for ( unsigned int t = 0 ; t < partitions[index_extended].logicals .size() ; t++ )
if ( partitions[index_extended].logicals[t].partition_number >
partition_original.partition_number )
partition_original->partition_number )
partitions[index_extended].logicals[t].Update_Number(
partitions[index_extended].logicals[t].partition_number -1 );
}
@ -96,17 +104,20 @@ void OperationDelete::apply_to_visual( PartitionVector & partitions )
void OperationDelete::create_description()
{
if ( partition_original.type == GParted::TYPE_LOGICAL )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_original->type == TYPE_LOGICAL )
description = _("Logical Partition") ;
else
description = partition_original .get_path() ;
description = partition_original->get_path();
/*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 345 MiB) from /dev/hda */
description = String::ucompose( _("Delete %1 (%2, %3) from %4"),
description,
Utils::get_filesystem_string( partition_original .filesystem ),
Utils::format_size( partition_original .get_sector_length(), partition_original .sector_size ),
partition_original .device_path ) ;
description,
Utils::get_filesystem_string( partition_original->filesystem ),
Utils::format_size( partition_original->get_sector_length(),
partition_original->sector_size ),
partition_original->device_path );
}
bool OperationDelete::merge_operations( const Operation & candidate )

View file

@ -28,13 +28,24 @@ OperationFormat::OperationFormat( const Device & device,
type = OPERATION_FORMAT ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationFormat::~OperationFormat()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationFormat::apply_to_visual( PartitionVector & partitions )
{
if ( partition_original.whole_device && partition_new.filesystem == FS_CLEARED )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_original->whole_device && partition_new->filesystem == FS_CLEARED )
{
// Make format to cleared whole disk device file system preview as
// unallocated device, matching what happens when implemented.
@ -57,18 +68,24 @@ void OperationFormat::apply_to_visual( PartitionVector & partitions )
void OperationFormat::create_description()
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
/*TO TRANSLATORS: looks like Format /dev/hda4 as linux-swap */
description = String::ucompose( _("Format %1 as %2"),
partition_original .get_path(),
Utils::get_filesystem_string( partition_new .filesystem ) ) ;
partition_original->get_path(),
Utils::get_filesystem_string( partition_new->filesystem ) );
}
bool OperationFormat::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_FORMAT &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
partition_new = candidate.get_partition_new();
delete partition_new;
partition_new = new Partition( candidate.get_partition_new() );
create_description();
return true;
}

View file

@ -28,8 +28,16 @@ OperationLabelFileSystem::OperationLabelFileSystem( const Device & device,
type = OPERATION_LABEL_FILESYSTEM;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationLabelFileSystem::~OperationLabelFileSystem()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationLabelFileSystem::apply_to_visual( PartitionVector & partitions )
@ -39,24 +47,31 @@ void OperationLabelFileSystem::apply_to_visual( PartitionVector & partitions )
void OperationLabelFileSystem::create_description()
{
if( partition_new.get_filesystem_label().empty() ) {
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if( partition_new->get_filesystem_label().empty() )
{
/* TO TRANSLATORS: looks like Clear file system Label on /dev/hda3 */
description = String::ucompose( _("Clear file system label on %1"),
partition_new.get_path() );
} else {
partition_new->get_path() );
}
else
{
/* TO TRANSLATORS: looks like Set file system label "My Label" on /dev/hda3 */
description = String::ucompose( _("Set file system label \"%1\" on %2"),
partition_new.get_filesystem_label(),
partition_new.get_path() );
partition_new->get_filesystem_label(),
partition_new->get_path() );
}
}
bool OperationLabelFileSystem::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_LABEL_FILESYSTEM &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
partition_new.set_filesystem_label( candidate.get_partition_new().get_filesystem_label() );
partition_new->set_filesystem_label( candidate.get_partition_new().get_filesystem_label() );
create_description();
return true;
}

View file

@ -28,8 +28,16 @@ OperationNamePartition::OperationNamePartition( const Device & device,
type = OPERATION_NAME_PARTITION;
this->device = device.get_copy_without_partitions();
this->partition_original = partition_orig;
this->partition_new = partition_new;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationNamePartition::~OperationNamePartition()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationNamePartition::apply_to_visual( PartitionVector & partitions )
@ -39,27 +47,31 @@ void OperationNamePartition::apply_to_visual( PartitionVector & partitions )
void OperationNamePartition::create_description()
{
if( partition_new.name.empty() )
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if( partition_new->name.empty() )
{
/* TO TRANSLATORS: looks like Clear partition name on /dev/hda3 */
description = String::ucompose( _("Clear partition name on %1"),
partition_new.get_path() );
partition_new->get_path() );
}
else
{
/* TO TRANSLATORS: looks like Set partition name "My Name" on /dev/hda3 */
description = String::ucompose( _("Set partition name \"%1\" on %2"),
partition_new.name,
partition_new.get_path() );
partition_new->name,
partition_new->get_path() );
}
}
bool OperationNamePartition::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_NAME_PARTITION &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
partition_new.name = candidate.get_partition_new().name;
partition_new->name = candidate.get_partition_new().name;
create_description();
return true;
}

View file

@ -29,13 +29,23 @@ OperationResizeMove::OperationResizeMove( const Device & device,
type = OPERATION_RESIZE_MOVE ;
this->device = device.get_copy_without_partitions();
this ->partition_original = partition_orig ;
this ->partition_new = partition_new ;
this->partition_original = new Partition( partition_orig );
this->partition_new = new Partition( partition_new );
}
OperationResizeMove::~OperationResizeMove()
{
delete partition_original;
delete partition_new;
partition_original = NULL;
partition_new = NULL;
}
void OperationResizeMove::apply_to_visual( PartitionVector & partitions )
{
if ( partition_original .type == GParted::TYPE_EXTENDED )
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
if ( partition_original->type == TYPE_EXTENDED )
apply_extended_to_visual( partitions ) ;
else
apply_normal_to_visual( partitions ) ;
@ -43,6 +53,9 @@ void OperationResizeMove::apply_to_visual( PartitionVector & partitions )
void OperationResizeMove::create_description()
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
//i'm not too happy with this, but i think it is the correct way from a i18n POV
enum Action
{
@ -58,41 +71,46 @@ void OperationResizeMove::create_description()
} ;
Action action = NONE ;
if ( partition_new .get_sector_length() > partition_original .get_sector_length() ) {
if ( partition_new->get_sector_length() > partition_original->get_sector_length() )
{
//Grow partition
action = GROW ;
if ( partition_new .sector_start > partition_original .sector_start )
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT_GROW ;
if ( partition_new .sector_start < partition_original .sector_start )
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT_GROW ;
} else if ( partition_new .get_sector_length() < partition_original .get_sector_length() ) {
}
else if ( partition_new->get_sector_length() < partition_original->get_sector_length() )
{
//Shrink partition
action = SHRINK ;
if ( partition_new .sector_start > partition_original .sector_start )
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT_SHRINK ;
if ( partition_new .sector_start < partition_original .sector_start )
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT_SHRINK ;
} else {
}
else
{
//No change in partition size
if ( partition_new .sector_start > partition_original .sector_start )
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT ;
if ( partition_new .sector_start < partition_original .sector_start )
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT ;
}
switch ( action )
{
case NONE :
description = String::ucompose( _("resize/move %1"), partition_original .get_path() ) ;
description = String::ucompose( _("resize/move %1"), partition_original->get_path() );
description += " (" ;
description += _("new and old partition have the same size and position. Hence continuing anyway") ;
description += ")" ;
break ;
case MOVE_RIGHT :
description = String::ucompose( _("Move %1 to the right"), partition_original .get_path() ) ;
description = String::ucompose( _("Move %1 to the right"), partition_original->get_path() );
break ;
case MOVE_LEFT :
description = String::ucompose( _("Move %1 to the left"), partition_original .get_path() ) ;
description = String::ucompose( _("Move %1 to the left"), partition_original->get_path() );
break ;
case GROW :
description = _("Grow %1 from %2 to %3") ;
@ -116,17 +134,22 @@ void OperationResizeMove::create_description()
if ( ! description .empty() && action != NONE && action != MOVE_LEFT && action != MOVE_RIGHT )
description = String::ucompose( description,
partition_original .get_path(),
Utils::format_size( partition_original .get_sector_length(), partition_original .sector_size ),
Utils::format_size( partition_new .get_sector_length(), partition_new .sector_size ) ) ;
partition_original->get_path(),
Utils::format_size( partition_original->get_sector_length(),
partition_original->sector_size ),
Utils::format_size( partition_new->get_sector_length(),
partition_new->sector_size ) );
}
void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
{
g_assert( partition_original != NULL ); // Bug: Not initialised by constructor or reset later
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
int index_extended;
int index;
if ( partition_original .inside_extended )
if ( partition_original->inside_extended )
{
index_extended = find_index_extended( partitions ) ;
@ -136,7 +159,7 @@ void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
if ( index >= 0 )
{
partitions[index_extended].logicals[index] = partition_new;
partitions[index_extended].logicals[index] = *partition_new;
remove_adjacent_unallocated( partitions[index_extended].logicals, index );
insert_unallocated( partitions[index_extended].logicals,
@ -153,7 +176,7 @@ void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
if ( index >= 0 )
{
partitions[ index ] = partition_new ;
partitions[index] = *partition_new;
remove_adjacent_unallocated( partitions, index ) ;
insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
@ -163,6 +186,8 @@ void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
void OperationResizeMove::apply_extended_to_visual( PartitionVector & partitions )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
int index_extended;
//stuff OUTSIDE extended partition
@ -175,8 +200,8 @@ void OperationResizeMove::apply_extended_to_visual( PartitionVector & partitions
index_extended = find_index_extended( partitions ) ;
if ( index_extended >= 0 )
{
partitions[ index_extended ] .sector_start = partition_new .sector_start ;
partitions[ index_extended ] .sector_end = partition_new .sector_end ;
partitions[index_extended].sector_start = partition_new->sector_start;
partitions[index_extended].sector_end = partition_new->sector_end;
}
insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
@ -217,10 +242,13 @@ void OperationResizeMove::remove_adjacent_unallocated( PartitionVector & partiti
bool OperationResizeMove::merge_operations( const Operation & candidate )
{
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_RESIZE_MOVE &&
partition_new == candidate.get_partition_original() )
*partition_new == candidate.get_partition_original() )
{
partition_new = candidate.get_partition_new();
delete partition_new;
partition_new = new Partition( candidate.get_partition_new() );
create_description();
return true;
}