gparted/src/OperationChangeUUID.cc

91 lines
3.1 KiB
C++
Raw Normal View History

/* Copyright (C) 2012 Rogier Goossens
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "../include/OperationChangeUUID.h"
#include "../include/Partition.h"
#include "../include/PartitionVector.h"
namespace GParted
{
OperationChangeUUID::OperationChangeUUID( const Device & device
, const Partition & partition_orig
, const Partition & partition_new
)
{
type = OPERATION_CHANGE_UUID ;
this->device = device.get_copy_without_partitions();
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
2015-09-20 03:50:57 -06:00
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 )
{
substitute_new( partitions );
}
void OperationChangeUUID::create_description()
{
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
2015-09-20 03:50:57 -06:00
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 */
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
2015-09-20 03:50:57 -06:00
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 */
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
2015-09-20 03:50:57 -06:00
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 )
{
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
2015-09-20 03:50:57 -06:00
g_assert( partition_new != NULL ); // Bug: Not initialised by constructor or reset later
if ( candidate.type == OPERATION_CHANGE_UUID &&
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
2015-09-20 03:50:57 -06:00
*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 )
{
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
2015-09-20 03:50:57 -06:00
partition_new->uuid = candidate.get_partition_new().uuid;
create_description();
}
// Else no change required to this operation to merge candidate
return true;
}
return false;
}
} //GParted