Git commit 279159ca6f65eac74e78356097ba194bc9aa9341 by Andrius =C5=A0tikona= s. Committed on 31/03/2018 at 20:49. Pushed by stikonas into branch 'kauth'. Use smart pointers for CoreBackendPartitionTable. M +1 -3 src/backend/corebackend.h M +2 -1 src/backend/corebackenddevice.h M +8 -1 src/backend/corebackendmanager.cpp D +0 -30 src/backend/corebackendmanager_p.h M +1 -3 src/jobs/createfilesystemjob.cpp M +1 -3 src/jobs/createpartitionjob.cpp M +1 -4 src/jobs/deletefilesystemjob.cpp M +1 -4 src/jobs/deletepartitionjob.cpp M +1 -3 src/jobs/resizefilesystemjob.cpp M +1 -1 src/jobs/restorefilesystemjob.cpp M +1 -3 src/jobs/setpartflagsjob.cpp M +1 -3 src/jobs/setpartgeometryjob.cpp M +2 -9 src/plugins/dummy/dummydevice.cpp M +1 -1 src/plugins/dummy/dummydevice.h M +2 -2 src/plugins/sfdisk/sfdiskdevice.cpp M +1 -1 src/plugins/sfdisk/sfdiskdevice.h https://commits.kde.org/kpmcore/279159ca6f65eac74e78356097ba194bc9aa9341 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 fa= iled. 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 fa= iled. */ virtual std::unique_ptr openDevice(const Device& d)= =3D 0; = diff --git a/src/backend/corebackenddevice.h b/src/backend/corebackenddevic= e.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() =3D 0; + virtual std::unique_ptr openPartitionTable(= ) =3D 0; = /** * Create a new partition table on this device. diff --git a/src/backend/corebackendmanager.cpp b/src/backend/corebackendma= nager.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/corebackendma= nager_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 =C5=A0tikonas = * - * * - * 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/createfilesystemjo= b.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 =3D CoreB= ackendManager::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D b= ackendDevice->openPartitionTable(); + std::unique_ptr backendPart= itionTable =3D 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", "Fa= iled 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 syste= m type for partition %2.", device().deviceNode(), part= ition().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 =3D CoreBackendMa= nager::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDe= vice->openPartitionTable(); + std::unique_ptr backendPartitionTab= le =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { QString partitionPath =3D backendPartitionTable->createPar= tition(*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.", par= tition().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/deletefilesystemjo= b.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 =3D CoreBackendMa= nager::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDe= vice->openPartitionTable(); + std::unique_ptr backendPartitionTab= le =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { rval =3D 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 =3D CoreBackendMa= nager::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDe= vice->openPartitionTable(); + std::unique_ptr backendPartitionTab= le =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { rval =3D backendPartitionTable->deletePartition(*report, p= artition()); @@ -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/resizefilesystemjo= b.cpp index d86108a..f27bd70 100644 --- a/src/jobs/resizefilesystemjob.cpp +++ b/src/jobs/resizefilesystemjob.cpp @@ -117,7 +117,7 @@ bool ResizeFileSystemJob::resizeFileSystemBackend(Repor= t& report) std::unique_ptr backendDevice =3D CoreBackendManage= r::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDevice= ->openPartitionTable(); + std::unique_ptr backendPartitionTable = =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { connect(CoreBackendManager::self()->backend(), &CoreBackend::p= rogress, this, &ResizeFileSystemJob::progress); @@ -128,8 +128,6 @@ bool ResizeFileSystemJob::resizeFileSystemBackend(Repor= t& report) report.line() << xi18nc("@info:progress", "Successfully re= sized file system using internal backend functions."); backendPartitionTable->commit(); } - - delete backendPartitionTable; } else report.line() << xi18nc("@info:progress", "Could not open part= ition %1 while trying to resize the file system.", par= tition().deviceNode()); = diff --git a/src/jobs/restorefilesystemjob.cpp b/src/jobs/restorefilesystem= job.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 =3D FileSystem::Unknown; = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D b= ackendDevice->openPartitionTable(); + std::unique_ptr backendPart= itionTable =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) t =3D backendPartitionTable->detectFileSystemBySec= tor(*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 =3D CoreBackendManage= r::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDevice= ->openPartitionTable(); + std::unique_ptr backendPartitionTable = =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { int count =3D 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 par= tition table on device %1 to set partition flags for p= artition %2.", device().deviceNode(), partition().devi= ceNode()); } 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 =3D CoreBackendMa= nager::self()->backend()->openDevice(device()); = if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable =3D backendDe= vice->openPartitionTable(); + std::unique_ptr backendPartitionTab= le =3D backendDevice->openPartitionTable(); = if (backendPartitionTable) { rval =3D backendPartitionTable->updateGeometry(*report, pa= rtition(), 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 dev= ice %1 while trying to resize/move partition %2.", device().deviceNode(), partition().deviceNode()); diff --git a/src/plugins/dummy/dummydevice.cpp b/src/plugins/dummy/dummydev= ice.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 =3D new DummyPartitionTable(); - - if (ptable =3D=3D nullptr || !ptable->open()) { - delete ptable; - ptable =3D nullptr; - } - - return ptable; + return std::make_unique(DummyPartitionTable()); } = bool DummyDevice::createPartitionTable(Report& report, const PartitionTabl= e& ptable) diff --git a/src/plugins/dummy/dummydevice.h b/src/plugins/dummy/dummydevic= e.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() overri= de; = bool createPartitionTable(Report& report, const PartitionTable& ptable= ) override; }; diff --git a/src/plugins/sfdisk/sfdiskdevice.cpp b/src/plugins/sfdisk/sfdis= kdevice.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::openPartitionTabl= e() { - return new SfdiskPartitionTable(m_device); + return std::make_unique(m_device); } = bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTab= le& ptable) diff --git a/src/plugins/sfdisk/sfdiskdevice.h b/src/plugins/sfdisk/sfdiskd= evice.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() overri= de; = bool createPartitionTable(Report& report, const PartitionTable& ptable= ) override; =20