diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 11d607853..6d559c6fb 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -179,7 +179,7 @@ Branding::Branding( const QString& brandingFilePath, } catch ( YAML::Exception& e ) { - cDebug() << "WARNING: YAML parser error " << e.what(); + cDebug() << "WARNING: YAML parser error " << e.what() << "in" << file.fileName(); } QDir translationsDir( componentDir.filePath( "lang" ) ); diff --git a/src/libcalamaresui/Settings.cpp b/src/libcalamaresui/Settings.cpp index 719f950fe..ce01bf42d 100644 --- a/src/libcalamaresui/Settings.cpp +++ b/src/libcalamaresui/Settings.cpp @@ -156,7 +156,7 @@ Settings::Settings( const QString& settingsFilePath, } catch ( YAML::Exception& e ) { - cDebug() << "WARNING: YAML parser error " << e.what(); + cDebug() << "WARNING: YAML parser error " << e.what() << "in" << file.fileName(); } } else diff --git a/src/libcalamaresui/utils/YamlUtils.cpp b/src/libcalamaresui/utils/YamlUtils.cpp index 1eb759963..4b1a8fd86 100644 --- a/src/libcalamaresui/utils/YamlUtils.cpp +++ b/src/libcalamaresui/utils/YamlUtils.cpp @@ -18,8 +18,11 @@ */ #include "YamlUtils.h" +#include "utils/Logger.h" + #include +#include #include void @@ -105,4 +108,42 @@ yamlMapToVariant( const YAML::Node& mapNode ) } +void +explainYamlException( const YAML::Exception& e, const QByteArray& yamlData, const char *label ) +{ + cDebug() << "WARNING: YAML error " << e.what() << "in" << label << '.'; + if ( ( e.mark.line >= 0 ) && ( e.mark.column >= 0 ) ) + { + // Try to show the line where it happened. + int linestart = 0; + for ( int linecount = 0; linecount < e.mark.line; ++linecount ) + { + linestart = yamlData.indexOf( '\n', linestart ); + // No more \ns found, weird + if ( linestart < 0 ) + break; + linestart += 1; // Skip that \n + } + int lineend = linestart; + if ( linestart >= 0 ) + { + lineend = yamlData.indexOf( '\n', linestart ); + if ( lineend < 0 ) + lineend = yamlData.length(); + } + + int rangestart = linestart; + int rangeend = lineend; + // Adjust range (linestart..lineend) so it's not too long + if ( ( linestart >= 0 ) && ( e.mark.column > 30 ) ) + rangestart += ( e.mark.column - 30 ); + if ( ( linestart >= 0 ) && ( rangeend - rangestart > 40 ) ) + rangeend = rangestart + 40; + + if ( linestart >= 0 ) + cDebug() << "WARNING: offending YAML data:" << yamlData.mid( rangestart, rangeend-rangestart ).constData(); + + } } + +} // namespace diff --git a/src/libcalamaresui/utils/YamlUtils.h b/src/libcalamaresui/utils/YamlUtils.h index a39934f51..1da36178c 100644 --- a/src/libcalamaresui/utils/YamlUtils.h +++ b/src/libcalamaresui/utils/YamlUtils.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,9 +23,12 @@ #include #include +class QByteArray; + namespace YAML { class Node; +class Exception; } void operator>>( const YAML::Node& node, QStringList& v ); @@ -37,6 +41,13 @@ QVariant yamlScalarToVariant( const YAML::Node& scalarNode ); QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode ); QVariant yamlMapToVariant( const YAML::Node& mapNode ); +/** + * Given an exception from the YAML parser library, explain + * what is going on in terms of the data passed to the parser. + * Uses @p label when labeling the data source (e.g. "netinstall data") + */ +void explainYamlException( const YAML::Exception& e, const QByteArray& data, const char *label ); + } //ns #endif // YAMLUTILS_H diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 8017a739c..a4cc5c734 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -35,8 +35,6 @@ FinishedViewStep::FinishedViewStep( QObject* parent ) , m_widget( new FinishedPage() ) , installFailed( false ) { - cDebug() << "FinishedViewStep()"; - auto jq = Calamares::JobQueue::instance(); connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed ); @@ -64,7 +62,6 @@ FinishedViewStep::prettyName() const QWidget* FinishedViewStep::widget() { - cDebug() << "FinishedViewStep::widget()"; return m_widget; } @@ -140,7 +137,6 @@ FinishedViewStep::sendNotification() void FinishedViewStep::onActivate() { - cDebug() << "FinishedViewStep::onActivate()"; m_widget->setUpRestart(); sendNotification(); @@ -150,7 +146,6 @@ FinishedViewStep::onActivate() QList< Calamares::job_ptr > FinishedViewStep::jobs() const { - cDebug() << "FinishedViewStep::jobs"; return QList< Calamares::job_ptr >(); } diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index 24719b1be..8f38e7f14 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -116,28 +116,37 @@ LocaleViewStep::fetchGeoIpTimezone() { if ( reply->error() == QNetworkReply::NoError ) { - YAML::Node doc = YAML::Load( reply->readAll() ); + QByteArray data = reply->readAll(); - QVariant var = CalamaresUtils::yamlToVariant( doc ); - if ( !var.isNull() && - var.isValid() && - var.type() == QVariant::Map ) + try { - QVariantMap map = var.toMap(); - if ( map.contains( "time_zone" ) && - !map.value( "time_zone" ).toString().isEmpty() ) + YAML::Node doc = YAML::Load( reply->readAll() ); + + QVariant var = CalamaresUtils::yamlToVariant( doc ); + if ( !var.isNull() && + var.isValid() && + var.type() == QVariant::Map ) { - QString timezoneString = map.value( "time_zone" ).toString(); - QStringList timezone = timezoneString.split( '/', QString::SkipEmptyParts ); - if ( timezone.size() >= 2 ) + QVariantMap map = var.toMap(); + if ( map.contains( "time_zone" ) && + !map.value( "time_zone" ).toString().isEmpty() ) { - cDebug() << "GeoIP reporting" << timezoneString; - QString region = timezone.takeFirst(); - QString zone = timezone.join( '/' ); - m_startingTimezone = qMakePair( region, zone ); + QString timezoneString = map.value( "time_zone" ).toString(); + QStringList timezone = timezoneString.split( '/', QString::SkipEmptyParts ); + if ( timezone.size() >= 2 ) + { + cDebug() << "GeoIP reporting" << timezoneString; + QString region = timezone.takeFirst(); + QString zone = timezone.join( '/' ); + m_startingTimezone = qMakePair( region, zone ); + } } } } + catch ( YAML::Exception& e ) + { + CalamaresUtils::explainYamlException( e, data, "GeoIP data"); + } } reply->deleteLater(); diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index b5fa702d6..7bfda320c 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -64,14 +64,28 @@ NetInstallPage::isReady() return true; } -void NetInstallPage::readGroups( const QByteArray& yamlData ) +bool +NetInstallPage::readGroups( const QByteArray& yamlData ) { - YAML::Node groups = YAML::Load( yamlData.constData() ); - Q_ASSERT( groups.IsSequence() ); - m_groups = new PackageModel( groups ); - CALAMARES_RETRANSLATE( - m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) ); - m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Description" ) ); ) + try + { + YAML::Node groups = YAML::Load( yamlData.constData() ); + + if ( !groups.IsSequence() ) + cDebug() << "WARNING: netinstall groups data does not form a sequence."; + Q_ASSERT( groups.IsSequence() ); + m_groups = new PackageModel( groups ); + CALAMARES_RETRANSLATE( + m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) ); + m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Description" ) ); ) + return true; + + } + catch ( YAML::Exception& e ) + { + CalamaresUtils::explainYamlException( e, yamlData, "netinstall groups data" ); + return false; + } } void @@ -84,7 +98,13 @@ NetInstallPage::dataIsHere( QNetworkReply* reply ) return; } - readGroups( reply->readAll() ); + if ( !readGroups( reply->readAll() ) ) + { + cDebug() << "Netinstall groups data was received, but invalid."; + ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) ); + reply->deleteLater(); + return; + } ui->groupswidget->setModel( m_groups ); ui->groupswidget->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents ); diff --git a/src/modules/netinstall/NetInstallPage.h b/src/modules/netinstall/NetInstallPage.h index 7ecc74f89..423c16b8e 100644 --- a/src/modules/netinstall/NetInstallPage.h +++ b/src/modules/netinstall/NetInstallPage.h @@ -2,6 +2,7 @@ * Copyright 2016, Luca Giambonini * Copyright 2016, Lisa Vitolo * Copyright 2017, Kyle Robbertze + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +68,7 @@ private: // Takes the YAML data representing the groups and reads them into the // m_groups and m_groupOrder internal structures. See the README.md // of this module to know the format expected of the YAML files. - void readGroups( const QByteArray& yamlData ); + bool readGroups( const QByteArray& yamlData ); Ui::Page_NetInst* ui; diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 5f64b6530..0291c46e4 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -8,6 +8,10 @@ find_package( KF5 REQUIRED CoreAddons ) # These are needed because KPMcore links publicly against ConfigCore, I18n, IconThemes, KIOCore and Service find_package( KF5 REQUIRED Config I18n IconThemes KIO Service ) +find_package( KPMcore 3.1.50 ) +if ( ${KPMcore_FOUND} ) + add_definitions(-DWITH_KPMCORE22) +endif() find_package( KPMcore 3.0.3 REQUIRED ) find_library( atasmart_LIB atasmart ) find_library( blkid_LIB blkid ) diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index fc93b6bd7..6ed167eee 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -23,6 +23,7 @@ #include "core/PartitionIterator.h" // KPMcore +#include #include #include #include @@ -114,7 +115,11 @@ createNewPartition( PartitionNode* parent, qint64 lastSector, PartitionTable::Flags flags ) { - FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector ); + FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector +#ifdef WITH_KPMCORE22 + ,device.logicalSize() +#endif + ); return new Partition( parent, device, @@ -147,7 +152,11 @@ createNewEncryptedPartition( PartitionNode* parent, FS::luks* fs = dynamic_cast< FS::luks* >( FileSystemFactory::create( FileSystem::Luks, firstSector, - lastSector ) ); + lastSector +#ifdef WITH_KPMCORE22 + ,device.logicalSize() +#endif + ) ); if ( !fs ) { qDebug() << "ERROR: cannot create LUKS filesystem. Giving up."; @@ -177,6 +186,9 @@ clonePartition( Device* device, Partition* partition ) partition->fileSystem().type(), partition->firstSector(), partition->lastSector() +#ifdef WITH_KPMCORE22 + ,device->logicalSize() +#endif ); return new Partition( partition->parent(), *device, diff --git a/src/modules/partition/tests/PartitionJobTests.cpp b/src/modules/partition/tests/PartitionJobTests.cpp index 5a09bbab5..fe869232b 100644 --- a/src/modules/partition/tests/PartitionJobTests.cpp +++ b/src/modules/partition/tests/PartitionJobTests.cpp @@ -217,7 +217,11 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti lastSector = firstSector + size / m_device->logicalSize(); else lastSector = freeSpacePartition->lastSector(); - FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector ); + FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector +#ifdef WITH_KPMCORE22 + ,m_device->logicalSize() +#endif + ); Partition* partition = new Partition( freeSpacePartition->parent(),