diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h index c2e1153..e44b740 100644 --- a/src/backend/corebackend.h +++ b/src/backend/corebackend.h @@ -132,9 +132,7 @@ public: /** * Open a device for reading. * @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 - * an instance is returned, it's the caller's responsibility to delete the - * object. + * @return a pointer to a CoreBackendDevice or nullptr if the open failed. */ virtual std::unique_ptr openDevice(const Device& d) = 0; diff --git a/src/backend/corebackenddevice.h b/src/backend/corebackenddevice.h index b3c3126..0629f33 100644 --- a/src/backend/corebackenddevice.h +++ b/src/backend/corebackenddevice.h @@ -19,6 +19,7 @@ #define KPMCORE_COREBACKENDDEVICE_H +#include #include class CoreBackendPartition; @@ -81,7 +82,7 @@ public: * @return a pointer to the CoreBackendPartitionTable for this device or nullptr in case * of errors */ - virtual CoreBackendPartitionTable* openPartitionTable() = 0; + virtual std::unique_ptr openPartitionTable() = 0; /** * Create a new partition table on this device. diff --git a/src/backend/corebackendmanager.cpp b/src/backend/corebackendmanager.cpp index db60de9..1fbca68 100644 --- a/src/backend/corebackendmanager.cpp +++ b/src/backend/corebackendmanager.cpp @@ -18,7 +18,6 @@ *************************************************************************/ #include "backend/corebackendmanager.h" -#include "backend/corebackendmanager_p.h" #include "backend/corebackend.h" #include @@ -35,6 +34,14 @@ #include #include +struct CoreBackendManagerPrivate +{ + KAuth::ExecuteJob *m_job; + CoreBackend *m_Backend; + + QString m_Uuid; +}; + CoreBackendManager::CoreBackendManager() : d(std::make_unique()) { diff --git a/src/backend/corebackendmanager_p.h b/src/backend/corebackendmanager_p.h deleted file mode 100644 index d28bcb4..0000000 --- a/src/backend/corebackendmanager_p.h +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************* - * Copyright (C) 2018 by Andrius Štikonas * - * * - * 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 .* - *************************************************************************/ - -#ifndef KPMCORE_COREBACKENDMANAGER_P_H - -#define KPMCORE_COREBACKENDMANAGER_P_H - -struct CoreBackendManagerPrivate -{ - KAuth::ExecuteJob *m_job; - CoreBackend *m_Backend; - - QString m_Uuid; -}; - -#endif diff --git a/src/jobs/createfilesystemjob.cpp b/src/jobs/createfilesystemjob.cpp index ad20db7..09e63a2 100644 --- a/src/jobs/createfilesystemjob.cpp +++ b/src/jobs/createfilesystemjob.cpp @@ -63,7 +63,7 @@ bool CreateFileSystemJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { if (backendPartitionTable->setPartitionSystemType(*report, partition())) { @@ -71,8 +71,6 @@ bool CreateFileSystemJob::run(Report& parent) backendPartitionTable->commit(); } else report->line() << xi18nc("@info:progress", "Failed to set the system type for the file system on partition %1.", partition().deviceNode()); - - delete backendPartitionTable; } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); } else diff --git a/src/jobs/createpartitionjob.cpp b/src/jobs/createpartitionjob.cpp index dae4bf7..a67a132 100644 --- a/src/jobs/createpartitionjob.cpp +++ b/src/jobs/createpartitionjob.cpp @@ -54,7 +54,7 @@ bool CreatePartitionJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { QString partitionPath = backendPartitionTable->createPartition(*report, partition()); @@ -66,8 +66,6 @@ bool CreatePartitionJob::run(Report& parent) backendPartitionTable->commit(); } else report->line() << xi18nc("@info/plain", "Failed to add partition %1 to device %2.", partition().deviceNode(), device().deviceNode()); - - delete backendPartitionTable; } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to create new partition %2.", device().deviceNode(), partition().deviceNode()); } else diff --git a/src/jobs/deletefilesystemjob.cpp b/src/jobs/deletefilesystemjob.cpp index f01a3e3..6ff797e 100644 --- a/src/jobs/deletefilesystemjob.cpp +++ b/src/jobs/deletefilesystemjob.cpp @@ -77,7 +77,7 @@ bool DeleteFileSystemJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { 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 %1.", partition().deviceNode()); else backendPartitionTable->commit(); - - delete backendPartitionTable; - } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to delete file system on %2.", device().deviceNode(), partition().deviceNode()); diff --git a/src/jobs/deletepartitionjob.cpp b/src/jobs/deletepartitionjob.cpp index 293496c..20bada2 100644 --- a/src/jobs/deletepartitionjob.cpp +++ b/src/jobs/deletepartitionjob.cpp @@ -61,7 +61,7 @@ bool DeletePartitionJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { rval = backendPartitionTable->deletePartition(*report, partition()); @@ -70,9 +70,6 @@ bool DeletePartitionJob::run(Report& parent) report->line() << xi18nc("@info:progress", "Could not delete partition %1.", partition().deviceNode()); else backendPartitionTable->commit(); - - delete backendPartitionTable; - } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to delete partition %2.", device().deviceNode(), partition().deviceNode()); } else diff --git a/src/jobs/resizefilesystemjob.cpp b/src/jobs/resizefilesystemjob.cpp index d86108a..f27bd70 100644 --- a/src/jobs/resizefilesystemjob.cpp +++ b/src/jobs/resizefilesystemjob.cpp @@ -117,7 +117,7 @@ bool ResizeFileSystemJob::resizeFileSystemBackend(Report& report) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { 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."); backendPartitionTable->commit(); } - - delete backendPartitionTable; } else report.line() << xi18nc("@info:progress", "Could not open partition %1 while trying to resize the file system.", partition().deviceNode()); diff --git a/src/jobs/restorefilesystemjob.cpp b/src/jobs/restorefilesystemjob.cpp index a9265da..fc62906 100644 --- a/src/jobs/restorefilesystemjob.cpp +++ b/src/jobs/restorefilesystemjob.cpp @@ -85,7 +85,7 @@ bool RestoreFileSystemJob::run(Report& parent) FileSystem::Type t = FileSystem::Unknown; if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) t = backendPartitionTable->detectFileSystemBySector(*report, targetDevice(), targetPartition().firstSector()); diff --git a/src/jobs/setpartflagsjob.cpp b/src/jobs/setpartflagsjob.cpp index 33a3070..fceb583 100644 --- a/src/jobs/setpartflagsjob.cpp +++ b/src/jobs/setpartflagsjob.cpp @@ -59,7 +59,7 @@ bool SetPartFlagsJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { int count = 0; @@ -81,8 +81,6 @@ bool SetPartFlagsJob::run(Report& parent) if (rval) backendPartitionTable->commit(); - - delete backendPartitionTable; } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to set partition flags for partition %2.", device().deviceNode(), partition().deviceNode()); } else diff --git a/src/jobs/setpartgeometryjob.cpp b/src/jobs/setpartgeometryjob.cpp index 9c3a488..153c352 100644 --- a/src/jobs/setpartgeometryjob.cpp +++ b/src/jobs/setpartgeometryjob.cpp @@ -59,7 +59,7 @@ bool SetPartGeometryJob::run(Report& parent) std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { rval = backendPartitionTable->updateGeometry(*report, partition(), newStart(), newStart() + newLength() - 1); @@ -69,8 +69,6 @@ bool SetPartGeometryJob::run(Report& parent) partition().setLastSector(newStart() + newLength() - 1); backendPartitionTable->commit(); } - - delete backendPartitionTable; } } else report->line() << xi18nc("@info:progress", "Could not open device %1 while trying to resize/move partition %2.", device().deviceNode(), partition().deviceNode()); diff --git a/src/plugins/dummy/dummydevice.cpp b/src/plugins/dummy/dummydevice.cpp index d2b43e9..0ffa283 100644 --- a/src/plugins/dummy/dummydevice.cpp +++ b/src/plugins/dummy/dummydevice.cpp @@ -47,16 +47,9 @@ bool DummyDevice::close() return true; } -CoreBackendPartitionTable* DummyDevice::openPartitionTable() +std::unique_ptr DummyDevice::openPartitionTable() { - CoreBackendPartitionTable* ptable = new DummyPartitionTable(); - - if (ptable == nullptr || !ptable->open()) { - delete ptable; - ptable = nullptr; - } - - return ptable; + return std::make_unique(DummyPartitionTable()); } bool DummyDevice::createPartitionTable(Report& report, const PartitionTable& ptable) diff --git a/src/plugins/dummy/dummydevice.h b/src/plugins/dummy/dummydevice.h index 6895e65..746c346 100644 --- a/src/plugins/dummy/dummydevice.h +++ b/src/plugins/dummy/dummydevice.h @@ -41,7 +41,7 @@ public: bool openExclusive() override; bool close() override; - CoreBackendPartitionTable* openPartitionTable() override; + std::unique_ptr openPartitionTable() override; bool createPartitionTable(Report& report, const PartitionTable& ptable) override; }; diff --git a/src/plugins/sfdisk/sfdiskdevice.cpp b/src/plugins/sfdisk/sfdiskdevice.cpp index 7dfc248..d8e1887 100644 --- a/src/plugins/sfdisk/sfdiskdevice.cpp +++ b/src/plugins/sfdisk/sfdiskdevice.cpp @@ -58,9 +58,9 @@ bool SfdiskDevice::close() return true; } -CoreBackendPartitionTable* SfdiskDevice::openPartitionTable() +std::unique_ptr SfdiskDevice::openPartitionTable() { - return new SfdiskPartitionTable(m_device); + return std::make_unique(m_device); } bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& ptable) diff --git a/src/plugins/sfdisk/sfdiskdevice.h b/src/plugins/sfdisk/sfdiskdevice.h index 096dd74..eab4a12 100644 --- a/src/plugins/sfdisk/sfdiskdevice.h +++ b/src/plugins/sfdisk/sfdiskdevice.h @@ -42,7 +42,7 @@ public: bool openExclusive() override; bool close() override; - CoreBackendPartitionTable* openPartitionTable() override; + std::unique_ptr openPartitionTable() override; bool createPartitionTable(Report& report, const PartitionTable& ptable) override;