make API cleaner: don't use out param if a return value will do

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1128321
This commit is contained in:
Volker Lanz 2010-05-18 22:48:56 +00:00
parent d058abce6e
commit faa406a201
7 changed files with 12 additions and 21 deletions

3
TODO
View File

@ -12,9 +12,6 @@ Bugs to fix for 1.1:
* why does CoreBackendPartitionTable::detectFileSystemBySector() take a Device * why does CoreBackendPartitionTable::detectFileSystemBySector() take a Device
and not a CoreBackendDevice? and not a CoreBackendDevice?
* why can't CoreBackendPartitionTable::createPartition() return an int and use 0
or -1 as error code and otherwise return the new number?
=============================================================================== ===============================================================================
For releases after 1.1: For releases after 1.1:

View File

@ -104,11 +104,9 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendPartitionTable
* Create a new partition. * Create a new partition.
* @param report the report to write information to * @param report the report to write information to
* @param partition the new partition to create on disk * @param partition the new partition to create on disk
* @param new_number output value holding the new number the OS sees the partition under * @return the new number the OS sees the partition under (e.g. 7 for "/dev/sda7") or -1 on failure
* (e.g. 7 for "/dev/sda7")
* @return true on success
*/ */
virtual bool createPartition(Report& report, const Partition& partition, quint32& new_number) = 0; virtual qint32 createPartition(Report& report, const Partition& partition) = 0;
/** /**
* Update the geometry for a partition in the partition table. * Update the geometry for a partition in the partition table.

View File

@ -58,11 +58,11 @@ bool CreatePartitionJob::run(Report& parent)
if (backendPartitionTable) if (backendPartitionTable)
{ {
quint32 num = -1; qint32 num = backendPartitionTable->createPartition(*report, partition());
rval = backendPartitionTable->createPartition(*report, partition(), num);
if (rval) if (num > 0)
{ {
rval = true;
partition().setNumber(num); partition().setNumber(num);
partition().setState(Partition::StateNone); partition().setState(Partition::StateNone);
backendPartitionTable->commit(); backendPartitionTable->commit();

View File

@ -67,11 +67,10 @@ CoreBackendPartition* DummyPartitionTable::getPartitionBySector(qint64 sector)
return new DummyPartition(); return new DummyPartition();
} }
bool DummyPartitionTable::createPartition(Report& report, const Partition& partition, quint32& new_number) qint32 DummyPartitionTable::createPartition(Report& report, const Partition& partition)
{ {
Q_UNUSED(report); Q_UNUSED(report);
Q_UNUSED(partition); Q_UNUSED(partition);
Q_UNUSED(new_number);
return true; return true;
} }

View File

@ -45,7 +45,7 @@ class DummyPartitionTable : public CoreBackendPartitionTable
virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getExtendedPartition();
virtual CoreBackendPartition* getPartitionBySector(qint64 sector); virtual CoreBackendPartition* getPartitionBySector(qint64 sector);
virtual bool createPartition(Report& report, const Partition& partition, quint32& new_number); virtual qint32 createPartition(Report& report, const Partition& partition);
virtual bool deletePartition(Report& report, const Partition& partition); virtual bool deletePartition(Report& report, const Partition& partition);
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end);
virtual bool clobberFileSystem(Report& report, const Partition& partition); virtual bool clobberFileSystem(Report& report, const Partition& partition);

View File

@ -144,11 +144,11 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t)
return ped_file_system_type_get("ext2"); return ped_file_system_type_get("ext2");
} }
bool LibPartedPartitionTable::createPartition(Report& report, const Partition& partition, quint32& new_number) qint32 LibPartedPartitionTable::createPartition(Report& report, const Partition& partition)
{ {
Q_ASSERT(partition.devicePath() == pedDevice()->path); Q_ASSERT(partition.devicePath() == pedDevice()->path);
bool rval = false; qint32 rval = -1;
// According to libParted docs, PedPartitionType can be "NULL if unknown". That's obviously wrong, // According to libParted docs, PedPartitionType can be "NULL if unknown". That's obviously wrong,
// it's a typedef for an enum. So let's use something the libparted devs will hopefully never // it's a typedef for an enum. So let's use something the libparted devs will hopefully never
@ -187,14 +187,11 @@ bool LibPartedPartitionTable::createPartition(Report& report, const Partition& p
if (pedConstraint == NULL) if (pedConstraint == NULL)
{ {
report.line() << i18nc("@info/plain", "Failed to create a new partition: could not get geometry for constraint."); report.line() << i18nc("@info/plain", "Failed to create a new partition: could not get geometry for constraint.");
return false; return -1;
} }
if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint)) if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint))
{ rval = pedPartition->num;
new_number = pedPartition->num;
rval = true;
}
else else
report.line() << i18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), pedDisk()->dev->path); report.line() << i18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), pedDisk()->dev->path);

View File

@ -48,7 +48,7 @@ class LibPartedPartitionTable : public CoreBackendPartitionTable
virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getExtendedPartition();
virtual CoreBackendPartition* getPartitionBySector(qint64 sector); virtual CoreBackendPartition* getPartitionBySector(qint64 sector);
virtual bool createPartition(Report& report, const Partition& partition, quint32& new_number); virtual qint32 createPartition(Report& report, const Partition& partition);
virtual bool deletePartition(Report& report, const Partition& partition); virtual bool deletePartition(Report& report, const Partition& partition);
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end);
virtual bool clobberFileSystem(Report& report, const Partition& partition); virtual bool clobberFileSystem(Report& report, const Partition& partition);