[partition] Reduce direct dependency of PartUtils on PartitionCoreModule

This commit is contained in:
Corentin Noël 2020-10-05 11:39:04 +02:00
parent 063482339f
commit 08138f5a41
3 changed files with 9 additions and 12 deletions

View File

@ -11,8 +11,6 @@
#include "PartUtils.h" #include "PartUtils.h"
#include "PartitionCoreModule.h"
#include "core/DeviceModel.h" #include "core/DeviceModel.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "core/PartitionInfo.h" #include "core/PartitionInfo.h"
@ -198,13 +196,12 @@ canBeResized( Partition* candidate )
bool bool
canBeResized( PartitionCoreModule* core, const QString& partitionPath ) canBeResized( DeviceModel* dm, const QString& partitionPath )
{ {
cDebug() << "Checking if" << partitionPath << "can be resized."; cDebug() << "Checking if" << partitionPath << "can be resized.";
QString partitionWithOs = partitionPath; QString partitionWithOs = partitionPath;
if ( partitionWithOs.startsWith( "/dev/" ) ) if ( partitionWithOs.startsWith( "/dev/" ) )
{ {
DeviceModel* dm = core->deviceModel();
for ( int i = 0; i < dm->rowCount(); ++i ) for ( int i = 0; i < dm->rowCount(); ++i )
{ {
Device* dev = dm->deviceForIndex( dm->index( i ) ); Device* dev = dm->deviceForIndex( dm->index( i ) );
@ -358,7 +355,7 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& moun
OsproberEntryList OsproberEntryList
runOsprober( PartitionCoreModule* core ) runOsprober( DeviceModel* dm )
{ {
QString osproberOutput; QString osproberOutput;
QProcess osprober; QProcess osprober;
@ -406,7 +403,7 @@ runOsprober( PartitionCoreModule* core )
QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" ); QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" );
osproberEntries.append( osproberEntries.append(
{ prettyName, path, QString(), canBeResized( core, path ), lineColumns, fstabEntries, homePath } ); { prettyName, path, QString(), canBeResized( dm, path ), lineColumns, fstabEntries, homePath } );
osproberCleanLines.append( line ); osproberCleanLines.append( line );
} }
} }

View File

@ -22,7 +22,7 @@
// Qt // Qt
#include <QString> #include <QString>
class PartitionCoreModule; class DeviceModel;
class Partition; class Partition;
namespace PartUtils namespace PartUtils
@ -56,19 +56,19 @@ bool canBeResized( Partition* candidate );
/** /**
* @brief canBeReplaced checks whether the given Partition satisfies the criteria * @brief canBeReplaced checks whether the given Partition satisfies the criteria
* for resizing (shrinking) it to make room for a new OS. * for resizing (shrinking) it to make room for a new OS.
* @param core the PartitionCoreModule instance. * @param dm the DeviceModel instance.
* @param partitionPath the device path of the candidate partition to resize. * @param partitionPath the device path of the candidate partition to resize.
* @return true if the criteria are met, otherwise false. * @return true if the criteria are met, otherwise false.
*/ */
bool canBeResized( PartitionCoreModule* core, const QString& partitionPath ); bool canBeResized( DeviceModel* dm, const QString& partitionPath );
/** /**
* @brief runOsprober executes os-prober, parses the output and writes relevant * @brief runOsprober executes os-prober, parses the output and writes relevant
* data to GlobalStorage. * data to GlobalStorage.
* @param core the PartitionCoreModule instance. * @param dm the DeviceModel instance.
* @return a list of os-prober entries, parsed. * @return a list of os-prober entries, parsed.
*/ */
OsproberEntryList runOsprober( PartitionCoreModule* core ); OsproberEntryList runOsprober( DeviceModel* dm );
/** /**
* @brief Is this system EFI-enabled? Decides based on /sys/firmware/efi * @brief Is this system EFI-enabled? Decides based on /sys/firmware/efi

View File

@ -180,7 +180,7 @@ PartitionCoreModule::doInit()
// The following PartUtils::runOsprober call in turn calls PartUtils::canBeResized, // The following PartUtils::runOsprober call in turn calls PartUtils::canBeResized,
// which relies on a working DeviceModel. // which relies on a working DeviceModel.
m_osproberLines = PartUtils::runOsprober( this ); m_osproberLines = PartUtils::runOsprober( this->deviceModel() );
// We perform a best effort of filling out filesystem UUIDs in m_osproberLines // We perform a best effort of filling out filesystem UUIDs in m_osproberLines
// because we will need them later on in PartitionModel if partition paths // because we will need them later on in PartitionModel if partition paths