Use smart pointers for CoreBackendPartitionTable.
This commit is contained in:
parent
2527b3ecc3
commit
279159ca6f
|
@ -132,9 +132,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Open a device for reading.
|
* Open a device for reading.
|
||||||
* @param deviceNode The path of the device that is to be opened (e.g. /dev/sda)
|
* @param deviceNode The path of the device that is to be opened (e.g. /dev/sda)
|
||||||
* @return a pointer to a CoreBackendDevice or nullptr if the open failed. If a pointer to
|
* @return a pointer to a CoreBackendDevice or nullptr if the open failed.
|
||||||
* an instance is returned, it's the caller's responsibility to delete the
|
|
||||||
* object.
|
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<CoreBackendDevice> openDevice(const Device& d) = 0;
|
virtual std::unique_ptr<CoreBackendDevice> openDevice(const Device& d) = 0;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#define KPMCORE_COREBACKENDDEVICE_H
|
#define KPMCORE_COREBACKENDDEVICE_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class CoreBackendPartition;
|
class CoreBackendPartition;
|
||||||
|
@ -81,7 +82,7 @@ public:
|
||||||
* @return a pointer to the CoreBackendPartitionTable for this device or nullptr in case
|
* @return a pointer to the CoreBackendPartitionTable for this device or nullptr in case
|
||||||
* of errors
|
* of errors
|
||||||
*/
|
*/
|
||||||
virtual CoreBackendPartitionTable* openPartitionTable() = 0;
|
virtual std::unique_ptr<CoreBackendPartitionTable> openPartitionTable() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new partition table on this device.
|
* Create a new partition table on this device.
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "backend/corebackendmanager.h"
|
#include "backend/corebackendmanager.h"
|
||||||
#include "backend/corebackendmanager_p.h"
|
|
||||||
#include "backend/corebackend.h"
|
#include "backend/corebackend.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -35,6 +34,14 @@
|
||||||
#include <KPluginLoader>
|
#include <KPluginLoader>
|
||||||
#include <KPluginMetaData>
|
#include <KPluginMetaData>
|
||||||
|
|
||||||
|
struct CoreBackendManagerPrivate
|
||||||
|
{
|
||||||
|
KAuth::ExecuteJob *m_job;
|
||||||
|
CoreBackend *m_Backend;
|
||||||
|
|
||||||
|
QString m_Uuid;
|
||||||
|
};
|
||||||
|
|
||||||
CoreBackendManager::CoreBackendManager() :
|
CoreBackendManager::CoreBackendManager() :
|
||||||
d(std::make_unique<CoreBackendManagerPrivate>())
|
d(std::make_unique<CoreBackendManagerPrivate>())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*************************************************************************
|
|
||||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
|
||||||
* *
|
|
||||||
* 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 3 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/>.*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef KPMCORE_COREBACKENDMANAGER_P_H
|
|
||||||
|
|
||||||
#define KPMCORE_COREBACKENDMANAGER_P_H
|
|
||||||
|
|
||||||
struct CoreBackendManagerPrivate
|
|
||||||
{
|
|
||||||
KAuth::ExecuteJob *m_job;
|
|
||||||
CoreBackend *m_Backend;
|
|
||||||
|
|
||||||
QString m_Uuid;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -63,7 +63,7 @@ bool CreateFileSystemJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
if (backendPartitionTable->setPartitionSystemType(*report, partition())) {
|
if (backendPartitionTable->setPartitionSystemType(*report, partition())) {
|
||||||
|
@ -71,8 +71,6 @@ bool CreateFileSystemJob::run(Report& parent)
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Failed to set the system type for the file system on partition <filename>%1</filename>.", partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Failed to set the system type for the file system on partition <filename>%1</filename>.", partition().deviceNode());
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -54,7 +54,7 @@ bool CreatePartitionJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
QString partitionPath = backendPartitionTable->createPartition(*report, partition());
|
QString partitionPath = backendPartitionTable->createPartition(*report, partition());
|
||||||
|
@ -66,8 +66,6 @@ bool CreatePartitionJob::run(Report& parent)
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode());
|
report->line() << xi18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode());
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to create new partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to create new partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -77,7 +77,7 @@ bool DeleteFileSystemJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
rval = backendPartitionTable->clobberFileSystem(*report, partition());
|
rval = backendPartitionTable->clobberFileSystem(*report, partition());
|
||||||
|
@ -86,9 +86,6 @@ bool DeleteFileSystemJob::run(Report& parent)
|
||||||
report->line() << xi18nc("@info:progress", "Could not delete file system on <filename>%1</filename>.", partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not delete file system on <filename>%1</filename>.", partition().deviceNode());
|
||||||
else
|
else
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete file system on <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete file system on <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ bool DeletePartitionJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
rval = backendPartitionTable->deletePartition(*report, partition());
|
rval = backendPartitionTable->deletePartition(*report, partition());
|
||||||
|
@ -70,9 +70,6 @@ bool DeletePartitionJob::run(Report& parent)
|
||||||
report->line() << xi18nc("@info:progress", "Could not delete partition <filename>%1</filename>.", partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not delete partition <filename>%1</filename>.", partition().deviceNode());
|
||||||
else
|
else
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -117,7 +117,7 @@ bool ResizeFileSystemJob::resizeFileSystemBackend(Report& report)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
connect(CoreBackendManager::self()->backend(), &CoreBackend::progress, this, &ResizeFileSystemJob::progress);
|
connect(CoreBackendManager::self()->backend(), &CoreBackend::progress, this, &ResizeFileSystemJob::progress);
|
||||||
|
@ -128,8 +128,6 @@ bool ResizeFileSystemJob::resizeFileSystemBackend(Report& report)
|
||||||
report.line() << xi18nc("@info:progress", "Successfully resized file system using internal backend functions.");
|
report.line() << xi18nc("@info:progress", "Successfully resized file system using internal backend functions.");
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
} else
|
} else
|
||||||
report.line() << xi18nc("@info:progress", "Could not open partition <filename>%1</filename> while trying to resize the file system.", partition().deviceNode());
|
report.line() << xi18nc("@info:progress", "Could not open partition <filename>%1</filename> while trying to resize the file system.", partition().deviceNode());
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ bool RestoreFileSystemJob::run(Report& parent)
|
||||||
FileSystem::Type t = FileSystem::Unknown;
|
FileSystem::Type t = FileSystem::Unknown;
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable)
|
if (backendPartitionTable)
|
||||||
t = backendPartitionTable->detectFileSystemBySector(*report, targetDevice(), targetPartition().firstSector());
|
t = backendPartitionTable->detectFileSystemBySector(*report, targetDevice(), targetPartition().firstSector());
|
||||||
|
|
|
@ -59,7 +59,7 @@ bool SetPartFlagsJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -81,8 +81,6 @@ bool SetPartFlagsJob::run(Report& parent)
|
||||||
|
|
||||||
if (rval)
|
if (rval)
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to set partition flags for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to set partition flags for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -59,7 +59,7 @@ bool SetPartGeometryJob::run(Report& parent)
|
||||||
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
rval = backendPartitionTable->updateGeometry(*report, partition(), newStart(), newStart() + newLength() - 1);
|
rval = backendPartitionTable->updateGeometry(*report, partition(), newStart(), newStart() + newLength() - 1);
|
||||||
|
@ -69,8 +69,6 @@ bool SetPartGeometryJob::run(Report& parent)
|
||||||
partition().setLastSector(newStart() + newLength() - 1);
|
partition().setLastSector(newStart() + newLength() - 1);
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete backendPartitionTable;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open device <filename>%1</filename> while trying to resize/move partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not open device <filename>%1</filename> while trying to resize/move partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
|
|
|
@ -47,16 +47,9 @@ bool DummyDevice::close()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreBackendPartitionTable* DummyDevice::openPartitionTable()
|
std::unique_ptr<CoreBackendPartitionTable> DummyDevice::openPartitionTable()
|
||||||
{
|
{
|
||||||
CoreBackendPartitionTable* ptable = new DummyPartitionTable();
|
return std::make_unique<DummyPartitionTable>(DummyPartitionTable());
|
||||||
|
|
||||||
if (ptable == nullptr || !ptable->open()) {
|
|
||||||
delete ptable;
|
|
||||||
ptable = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ptable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DummyDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
|
bool DummyDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
bool openExclusive() override;
|
bool openExclusive() override;
|
||||||
bool close() override;
|
bool close() override;
|
||||||
|
|
||||||
CoreBackendPartitionTable* openPartitionTable() override;
|
std::unique_ptr<CoreBackendPartitionTable> openPartitionTable() override;
|
||||||
|
|
||||||
bool createPartitionTable(Report& report, const PartitionTable& ptable) override;
|
bool createPartitionTable(Report& report, const PartitionTable& ptable) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,9 +58,9 @@ bool SfdiskDevice::close()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreBackendPartitionTable* SfdiskDevice::openPartitionTable()
|
std::unique_ptr<CoreBackendPartitionTable> SfdiskDevice::openPartitionTable()
|
||||||
{
|
{
|
||||||
return new SfdiskPartitionTable(m_device);
|
return std::make_unique<SfdiskPartitionTable>(m_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
|
bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
bool openExclusive() override;
|
bool openExclusive() override;
|
||||||
bool close() override;
|
bool close() override;
|
||||||
|
|
||||||
CoreBackendPartitionTable* openPartitionTable() override;
|
std::unique_ptr<CoreBackendPartitionTable> openPartitionTable() override;
|
||||||
|
|
||||||
bool createPartitionTable(Report& report, const PartitionTable& ptable) override;
|
bool createPartitionTable(Report& report, const PartitionTable& ptable) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue