[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kpmcore/kauth] src: Use smart pointers for CoreBackendPartitionTable.
From:       Andrius_Å tikonas <null () kde ! org>
Date:       2018-03-31 20:49:29
Message-ID: E1f2NRJ-0003Vw-8M () code ! kde ! org
[Download RAW message or body]

Git commit 279159ca6f65eac74e78356097ba194bc9aa9341 by Andrius Å tikonas.
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 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<CoreBackendDevice> 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 <memory>
 #include <QString>
 
 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<CoreBackendPartitionTable> 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 <QCoreApplication>
@@ -35,6 +34,14 @@
 #include <KPluginLoader>
 #include <KPluginMetaData>
 
+struct CoreBackendManagerPrivate
+{
+    KAuth::ExecuteJob *m_job;
+    CoreBackend *m_Backend;
+
+    QString m_Uuid;
+};
+
 CoreBackendManager::CoreBackendManager() :
     d(std::make_unique<CoreBackendManagerPrivate>())
 {
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 <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
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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
                 if (backendDevice) {
-                    CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +                    \
std::unique_ptr<CoreBackendPartitionTable> 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 <filename>%1</filename>.", \
                partition().deviceNode());
-
-                        delete backendPartitionTable;
                     } 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());  } 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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
         if (backendDevice) {
-            CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +            \
std::unique_ptr<CoreBackendPartitionTable> 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 \
<filename>%1</filename> to device <filename>%2</filename>.", \
                partition().deviceNode(), device().deviceNode());
-
-                delete backendPartitionTable;
             } 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());  } 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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
         if (backendDevice) {
-            CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +            \
std::unique_ptr<CoreBackendPartitionTable> 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 <filename>%1</filename>.", partition().deviceNode());  else
                     backendPartitionTable->commit();
-
-                delete backendPartitionTable;
-
             } 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());  
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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
         if (backendDevice) {
-            CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +            \
std::unique_ptr<CoreBackendPartitionTable> 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 <filename>%1</filename>.", partition().deviceNode());  else
                     backendPartitionTable->commit();
-
-                delete backendPartitionTable;
-
             } 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());  } 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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
     if (backendDevice) {
-        CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +        \
std::unique_ptr<CoreBackendPartitionTable> 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 \
<filename>%1</filename> 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<CoreBackendPartitionTable> 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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
     if (backendDevice) {
-        CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +        \
std::unique_ptr<CoreBackendPartitionTable> 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 <filename>%1</filename> to set partition flags for partition \
<filename>%2</filename>.", 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<CoreBackendDevice> backendDevice = \
CoreBackendManager::self()->backend()->openDevice(device());  
         if (backendDevice) {
-            CoreBackendPartitionTable* backendPartitionTable = \
backendDevice->openPartitionTable(); +            \
std::unique_ptr<CoreBackendPartitionTable> 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 \
<filename>%1</filename> while trying to resize/move partition \
                <filename>%2</filename>.", 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<CoreBackendPartitionTable> DummyDevice::openPartitionTable()
 {
-    CoreBackendPartitionTable* ptable = new DummyPartitionTable();
-
-    if (ptable == nullptr || !ptable->open()) {
-        delete ptable;
-        ptable = nullptr;
-    }
-
-    return ptable;
+    return std::make_unique<DummyPartitionTable>(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<CoreBackendPartitionTable> 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<CoreBackendPartitionTable> SfdiskDevice::openPartitionTable()
 {
-    return new SfdiskPartitionTable(m_device);
+    return std::make_unique<SfdiskPartitionTable>(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<CoreBackendPartitionTable> openPartitionTable() override;
 
     bool createPartitionTable(Report& report, const PartitionTable& ptable) \
override;  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic