[libcalamares] Move PartitionIterator to partition service.

- Starting to centralize utility code for partitioning into
   libcalamares instead of scattered and weirdly shared between
   modules.
 - This particular commit breaks compiling the modules, though.
This commit is contained in:
Adriaan de Groot 2019-06-13 12:12:47 +02:00
parent f1822c2adb
commit d8dc512f45
6 changed files with 74 additions and 17 deletions

View file

@ -97,6 +97,30 @@ if( Qt5Xml_FOUND )
list( APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml ) list( APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml )
endif() endif()
### OPTIONAL KPMcore support
#
#
find_package( KPMcore 3.3 )
set_package_properties(
KPMcore PROPERTIES
PURPOSE "For partitioning service"
)
if ( KPMcore_FOUND )
find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore
find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore
if( KPMcore_VERSION VERSION_GREATER "3.3.70" AND KPMcore_VERSION VERSION_LESS "4.0" )
message( FATAL_ERROR "KPMCore beta versions are not supported" )
endif()
include_directories( ${KPMCORE_INCLUDE_DIR} )
list( APPEND libSources
partition/PartitionIterator.cpp
)
list( APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore )
endif()
### LIBRARY ### LIBRARY
# #
# #

View file

@ -2,7 +2,7 @@
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org> * Copyright 2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org> * Copyright 2017, 2019 Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -25,21 +25,27 @@
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/core/partitiontable.h> #include <kpmcore/core/partitiontable.h>
namespace CalamaresUtils
{
namespace Partition
{
using Partition = ::Partition;
PartitionIterator::PartitionIterator( PartitionTable* table ) PartitionIterator::PartitionIterator( PartitionTable* table )
: m_table( table ) : m_table( table )
{}
Partition*
PartitionIterator::operator*() const
{ {
return m_current;
} }
Partition* PartitionIterator::operator*() const { return m_current; }
void void
PartitionIterator::operator++() PartitionIterator::operator++()
{ {
if ( !m_current ) if ( !m_current )
{
return; return;
}
if ( m_current->hasChildren() ) if ( m_current->hasChildren() )
{ {
// Go to the first child // Go to the first child
@ -85,11 +91,14 @@ PartitionIterator
PartitionIterator::begin( Device* device ) PartitionIterator::begin( Device* device )
{ {
if ( !device ) if ( !device )
{
return PartitionIterator( nullptr ); return PartitionIterator( nullptr );
Q_ASSERT(device); }
PartitionTable* table = device->partitionTable(); PartitionTable* table = device->partitionTable();
if ( !table ) if ( !table )
{
return PartitionIterator( nullptr ); return PartitionIterator( nullptr );
}
return PartitionIterator::begin( table ); return PartitionIterator::begin( table );
} }
@ -101,7 +110,9 @@ PartitionIterator::begin( PartitionTable* table )
// Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR // Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR
// partition table. // partition table.
if ( children.isEmpty() ) if ( children.isEmpty() )
{
return it; return it;
}
it.m_current = children.first(); it.m_current = children.first();
return it; return it;
} }
@ -110,10 +121,14 @@ PartitionIterator
PartitionIterator::end( Device* device ) PartitionIterator::end( Device* device )
{ {
if ( !device ) if ( !device )
{
return PartitionIterator( nullptr ); return PartitionIterator( nullptr );
}
PartitionTable* table = device->partitionTable(); PartitionTable* table = device->partitionTable();
if ( !table ) if ( !table )
{
return PartitionIterator( nullptr ); return PartitionIterator( nullptr );
}
return PartitionIterator::end( table ); return PartitionIterator::end( table );
} }
@ -123,3 +138,6 @@ PartitionIterator::end( PartitionTable* table )
{ {
return PartitionIterator( table ); return PartitionIterator( table );
} }
} // namespace Partition
} // namespace CalamaresUtils

View file

@ -2,6 +2,7 @@
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org> * Copyright 2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2019, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,20 +18,34 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PARTITIONITERATOR_H #ifndef PARTITION_PARTITIONITERATOR_H
#define PARTITIONITERATOR_H #define PARTITION_PARTITIONITERATOR_H
class Device; class Device;
class Partition; class Partition;
class PartitionTable; class PartitionTable;
/** namespace CalamaresUtils
{
namespace Partition
{
/** @brief Iterator over KPMCore partitions
*
* A forward-only iterator to go through the partitions of a device, * A forward-only iterator to go through the partitions of a device,
* independently of whether they are primary, logical or extended. * independently of whether they are primary, logical or extended.
*
* An iterator can be created from a device (then it refers to the
* partition table of that device) or a partition table. The
* partition table must remain valid throughout iteration.
*
* A nullptr is valid, for an empty iterator.
*/ */
class PartitionIterator class PartitionIterator
{ {
public: public:
using Partition = ::Partition;
Partition* operator*() const; Partition* operator*() const;
void operator++(); void operator++();
@ -50,4 +65,7 @@ private:
Partition* m_current = nullptr; Partition* m_current = nullptr;
}; };
#endif /* PARTITIONITERATOR_H */ } // namespace Partition
} // namespace CalamaresUtils
#endif // PARTITION_PARTITIONITERATOR_H

View file

@ -21,7 +21,6 @@ if ( KPMcore_FOUND )
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES SOURCES
ResizeFSJob.cpp ResizeFSJob.cpp
${PROJECT_SOURCE_DIR}/src/modules/partition/core/PartitionIterator.cpp
LINK_PRIVATE_LIBRARIES LINK_PRIVATE_LIBRARIES
kpmcore kpmcore
calamares calamares

View file

@ -48,7 +48,6 @@ if ( KPMcore_FOUND )
core/PartitionActions.cpp core/PartitionActions.cpp
core/PartitionCoreModule.cpp core/PartitionCoreModule.cpp
core/PartitionInfo.cpp core/PartitionInfo.cpp
core/PartitionIterator.cpp
core/PartitionLayout.cpp core/PartitionLayout.cpp
core/PartitionModel.cpp core/PartitionModel.cpp
core/PartUtils.cpp core/PartUtils.cpp

View file

@ -5,7 +5,6 @@ set( PartitionModule_SOURCE_DIR .. )
set( partitionjobtests_SRCS set( partitionjobtests_SRCS
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp ${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp ${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp
${PartitionModule_SOURCE_DIR}/core/PartitionIterator.cpp
${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionJob.cpp ${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionJob.cpp
${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionTableJob.cpp ${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionTableJob.cpp
${PartitionModule_SOURCE_DIR}/jobs/DeletePartitionJob.cpp ${PartitionModule_SOURCE_DIR}/jobs/DeletePartitionJob.cpp