From 6726a926a439fc1ef37e9e3c2809613fd6a5e3fb Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Mon, 29 Mar 2021 12:44:34 -0600 Subject: [PATCH 1/8] [logUpload] Configurable upload size limit A key 'sizeLimit' added to uploadServer field in branding.desc to limit the size of logFile to upload. --- src/branding/default/branding.desc | 18 +++++++++++------- src/libcalamaresui/Branding.cpp | 6 ++++-- src/libcalamaresui/Branding.h | 2 +- src/libcalamaresui/ViewManager.cpp | 2 +- src/libcalamaresui/utils/Paste.cpp | 18 +++++++++++------- src/libcalamaresui/utils/TestPaste.cpp | 6 +++--- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 90f92b5f1..98e887e76 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -220,13 +220,17 @@ slideshowAPI: 2 # These options are to customize online uploading of logs to pastebins: -# - type : Defines the kind of pastebin service to be used. Currently -# it accepts two values: -# - none : disables the pastebin functionality -# - fiche : use fiche pastebin server -# - url : Defines the address of pastebin service to be used. -# Takes string as input. Important bits are the host and port, -# the scheme is not used. +# - type : Defines the kind of pastebin service to be used. Currently +# it accepts two values: +# - none : disables the pastebin functionality +# - fiche : use fiche pastebin server +# - url : Defines the address of pastebin service to be used. +# Takes string as input. Important bits are the host and port, +# the scheme is not used. +# - sizeLimit : Defines maximum size limit (in KiB) of log file to be pasted. +# Takes integer as input. If <=0, no limit will be forced, +# else only last 'n' KiB of log file will be pasted. uploadServer : type : "fiche" url : "http://termbin.com:9999" + sizeLimit : 20 diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 3668c0b4b..c074b7403 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -153,15 +153,17 @@ uploadServerFromMap( const QVariantMap& map ) QString typestring = map[ "type" ].toString(); QString urlstring = map[ "url" ].toString(); + qint64 sizeLimit = map[ "sizeLimit" ].toLongLong(); if ( typestring.isEmpty() || urlstring.isEmpty() ) { - return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl() ); + return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl(), -1 ); } bool bogus = false; // we don't care about type-name lookup success here return Branding::UploadServerInfo( names.find( typestring, bogus ), - QUrl( urlstring, QUrl::ParsingMode::StrictMode ) ); + QUrl( urlstring, QUrl::ParsingMode::StrictMode ), + sizeLimit ); } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 831b2adec..f36d3c58c 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -226,7 +226,7 @@ public: * This is both the type (which may be none, in which case the URL * is irrelevant and usually empty) and the URL for the upload. */ - using UploadServerInfo = QPair< UploadServerType, QUrl >; + using UploadServerInfo = std::tuple< UploadServerType, QUrl, qint64 >; UploadServerInfo uploadServer() const { return m_uploadServer; } /** diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 704655c8b..6e0240157 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -144,7 +144,7 @@ void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { bool shouldOfferWebPaste - = Calamares::Branding::instance()->uploadServer().first != Calamares::Branding::UploadServerType::None; + = std::get<2>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None; cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 40e314108..779a8aca0 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -30,7 +30,7 @@ using namespace CalamaresUtils::Units; * Returns an empty QByteArray() on any kind of error. */ STATICTEST QByteArray -logFileContents() +logFileContents( qint64 sizeLimit ) { const QString name = Logger::logFile(); QFile pasteSourceFile( name ); @@ -40,11 +40,15 @@ logFileContents() return QByteArray(); } QFileInfo fi( pasteSourceFile ); - if ( fi.size() > 16_KiB ) + sizeLimit *= 1024; //For KiB to bytes + cDebug() << "Log upload size limit was set to " << sizeLimit << " bytes"; + if ( fi.size() > sizeLimit and sizeLimit > 0 ) { - pasteSourceFile.seek( fi.size() - 16_KiB ); + // Fixme : this following line is not getting pasted + cDebug() << "Only last " << sizeLimit << " bytes of log file (" << fi.size() << ") uploaded" ; + pasteSourceFile.seek( fi.size() - sizeLimit ); } - return pasteSourceFile.read( 16_KiB ); + return pasteSourceFile.read( sizeLimit ); } @@ -101,7 +105,7 @@ ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* par QString CalamaresUtils::Paste::doLogUpload( QObject* parent ) { - auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer(); if ( !serverUrl.isValid() ) { cWarning() << "Upload configure with invalid URL"; @@ -113,7 +117,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent ) return QString(); } - QByteArray pasteData = logFileContents(); + QByteArray pasteData = logFileContents( sizeLimit ); if ( pasteData.isEmpty() ) { // An error has already been logged @@ -165,6 +169,6 @@ CalamaresUtils::Paste::doLogUploadUI( QWidget* parent ) bool CalamaresUtils::Paste::isEnabled() { - auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer(); return type != Calamares::Branding::UploadServerType::None; } diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index d21d6b81e..da55395e0 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -16,7 +16,7 @@ #include #include -extern QByteArray logFileContents(); +extern QByteArray logFileContents( qint64 sizeLimit ); extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent ); class TestPaste : public QObject @@ -37,13 +37,13 @@ TestPaste::testGetLogFile() { QFile::remove( Logger::logFile() ); // This test assumes nothing **else** has set up logging yet - QByteArray contentsOfLogfileBefore = logFileContents(); + QByteArray contentsOfLogfileBefore = logFileContents( 16 ); QVERIFY( contentsOfLogfileBefore.isEmpty() ); Logger::setupLogLevel( Logger::LOGDEBUG ); Logger::setupLogfile(); - QByteArray contentsOfLogfileAfterSetup = logFileContents(); + QByteArray contentsOfLogfileAfterSetup = logFileContents( 16 ); QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() ); } From 6a6557e320835e56165aa385c505e4f2b0c53426 Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Mon, 29 Mar 2021 13:22:56 -0600 Subject: [PATCH 2/8] [logUpload] fixes --- src/branding/default/branding.desc | 2 +- src/libcalamaresui/ViewManager.cpp | 2 +- src/libcalamaresui/utils/Paste.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 98e887e76..b95c47cfe 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -233,4 +233,4 @@ slideshowAPI: 2 uploadServer : type : "fiche" url : "http://termbin.com:9999" - sizeLimit : 20 + sizeLimit : -1 diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 6e0240157..61fc462ef 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -144,7 +144,7 @@ void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { bool shouldOfferWebPaste - = std::get<2>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None; + = std::get<0>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None; cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 779a8aca0..6d2142626 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -40,7 +40,7 @@ logFileContents( qint64 sizeLimit ) return QByteArray(); } QFileInfo fi( pasteSourceFile ); - sizeLimit *= 1024; //For KiB to bytes + sizeLimit = ( sizeLimit < 0 ) ? 1024*1024 : sizeLimit * 1024; //For KiB to bytes cDebug() << "Log upload size limit was set to " << sizeLimit << " bytes"; if ( fi.size() > sizeLimit and sizeLimit > 0 ) { From d109fc58563d3c5d5f2f49233b00245360e215fa Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Tue, 30 Mar 2021 08:13:29 -0600 Subject: [PATCH 3/8] [logUpload] suggestionsAndFixes --- src/libcalamaresui/Branding.cpp | 4 ++-- src/libcalamaresui/utils/Paste.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index c074b7403..74fd94a6e 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -153,7 +153,7 @@ uploadServerFromMap( const QVariantMap& map ) QString typestring = map[ "type" ].toString(); QString urlstring = map[ "url" ].toString(); - qint64 sizeLimit = map[ "sizeLimit" ].toLongLong(); + qint64 sizeLimitKiB = map[ "sizeLimit" ].toLongLong(); if ( typestring.isEmpty() || urlstring.isEmpty() ) { @@ -163,7 +163,7 @@ uploadServerFromMap( const QVariantMap& map ) bool bogus = false; // we don't care about type-name lookup success here return Branding::UploadServerInfo( names.find( typestring, bogus ), QUrl( urlstring, QUrl::ParsingMode::StrictMode ), - sizeLimit ); + sizeLimitKiB ); } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 6d2142626..56c944bd4 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -30,8 +30,10 @@ using namespace CalamaresUtils::Units; * Returns an empty QByteArray() on any kind of error. */ STATICTEST QByteArray -logFileContents( qint64 sizeLimit ) +logFileContents( qint64 sizeLimitKiB ) { + if( sizeLimitKiB == 0 ) + return QByteArray(); const QString name = Logger::logFile(); QFile pasteSourceFile( name ); if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) @@ -40,15 +42,16 @@ logFileContents( qint64 sizeLimit ) return QByteArray(); } QFileInfo fi( pasteSourceFile ); - sizeLimit = ( sizeLimit < 0 ) ? 1024*1024 : sizeLimit * 1024; //For KiB to bytes - cDebug() << "Log upload size limit was set to " << sizeLimit << " bytes"; - if ( fi.size() > sizeLimit and sizeLimit > 0 ) + if( sizeLimitKiB < 0 ) + sizeLimitKiB = 1024; + qint64 sizeLimitBytes = CalamaresUtils::KiBtoBytes( ( unsigned long long ) sizeLimitKiB ); + cDebug() << "Log upload size limit was set to" << sizeLimitKiB << "KiB"; + if ( fi.size() > sizeLimitBytes and sizeLimitBytes > 0 ) { - // Fixme : this following line is not getting pasted - cDebug() << "Only last " << sizeLimit << " bytes of log file (" << fi.size() << ") uploaded" ; - pasteSourceFile.seek( fi.size() - sizeLimit ); + cDebug() << "Only last" << sizeLimitBytes << "bytes of log file (sized" << fi.size() << "bytes) uploaded" ; + pasteSourceFile.seek( fi.size() - sizeLimitBytes + 1_KiB ); } - return pasteSourceFile.read( sizeLimit ); + return pasteSourceFile.read( sizeLimitBytes + 1_KiB ); } From b42f86f20f5db3c145bc04c829b8835c87cfdfeb Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Tue, 30 Mar 2021 08:28:30 -0600 Subject: [PATCH 4/8] [logUpload] suggestionsAndFixes-part2 --- src/libcalamaresui/utils/Paste.cpp | 6 +++--- src/libcalamaresui/utils/TestPaste.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 56c944bd4..377522333 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -108,7 +108,7 @@ ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* par QString CalamaresUtils::Paste::doLogUpload( QObject* parent ) { - auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimitKiB ] = Calamares::Branding::instance()->uploadServer(); if ( !serverUrl.isValid() ) { cWarning() << "Upload configure with invalid URL"; @@ -120,7 +120,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent ) return QString(); } - QByteArray pasteData = logFileContents( sizeLimit ); + QByteArray pasteData = logFileContents( sizeLimitKiB ); if ( pasteData.isEmpty() ) { // An error has already been logged @@ -172,6 +172,6 @@ CalamaresUtils::Paste::doLogUploadUI( QWidget* parent ) bool CalamaresUtils::Paste::isEnabled() { - auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimitKiB ] = Calamares::Branding::instance()->uploadServer(); return type != Calamares::Branding::UploadServerType::None; } diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index da55395e0..68e972907 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -16,7 +16,7 @@ #include #include -extern QByteArray logFileContents( qint64 sizeLimit ); +extern QByteArray logFileContents( qint64 sizeLimitKiB ); extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent ); class TestPaste : public QObject From c1aa0b581e159fe31fb305f49002cdd9a3478ca4 Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Thu, 1 Apr 2021 00:25:37 -0600 Subject: [PATCH 5/8] [logUpload] suggestionsAndFixes-part3 - Resolved the problem of incomplete log upload - sizeLimit = 0 fixed (turns off paste functionality) - Documentation update - sizeLimit < 0 now needs no hardcoded upper limit - Calamares::Branding::uploadServerFromMap() serves sizeLimit in bytes --- src/branding/default/branding.desc | 8 ++++--- src/libcalamaresui/Branding.cpp | 4 ++-- src/libcalamaresui/Branding.h | 5 +++-- src/libcalamaresui/ViewManager.cpp | 3 ++- src/libcalamaresui/utils/Paste.cpp | 29 ++++++++++++++------------ src/libcalamaresui/utils/TestPaste.cpp | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index b95c47cfe..938d9eeb2 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -227,9 +227,11 @@ slideshowAPI: 2 # - url : Defines the address of pastebin service to be used. # Takes string as input. Important bits are the host and port, # the scheme is not used. -# - sizeLimit : Defines maximum size limit (in KiB) of log file to be pasted. -# Takes integer as input. If <=0, no limit will be forced, -# else only last 'n' KiB of log file will be pasted. +# - sizeLimit : Defines maximum size limit (in KiB) of log file to be pasted. +# Takes integer as input. If < 0, no limit will be forced, +# else only last (approximately) 'n' KiB of log file will be pasted. +# Please note that upload size may be slightly over the limit (due +# to last minute logging), so provide a suitable value. uploadServer : type : "fiche" url : "http://termbin.com:9999" diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 74fd94a6e..82bd5c5f8 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -157,13 +157,13 @@ uploadServerFromMap( const QVariantMap& map ) if ( typestring.isEmpty() || urlstring.isEmpty() ) { - return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl(), -1 ); + return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl(), 0 ); } bool bogus = false; // we don't care about type-name lookup success here return Branding::UploadServerInfo( names.find( typestring, bogus ), QUrl( urlstring, QUrl::ParsingMode::StrictMode ), - sizeLimitKiB ); + ( sizeLimitKiB >=0 ) ? sizeLimitKiB * 1024 : -1 ); } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index f36d3c58c..ba49f87c3 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -223,8 +223,9 @@ public: /** @brief Upload server configuration * - * This is both the type (which may be none, in which case the URL - * is irrelevant and usually empty) and the URL for the upload. + * This object has 3 items : the type (which may be none, in which case the URL + * is irrelevant and usually empty), the URL for the upload and the size limit of upload + * in bytes (for configuration value < 0, it serves -1, which stands for having no limit). */ using UploadServerInfo = std::tuple< UploadServerType, QUrl, qint64 >; UploadServerInfo uploadServer() const { return m_uploadServer; } diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 61fc462ef..3a8360e25 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -144,7 +144,8 @@ void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { bool shouldOfferWebPaste - = std::get<0>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None; + = std::get<0>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None + and std::get<2>(Calamares::Branding::instance()->uploadServer()) != 0; cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 377522333..642b45004 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -30,10 +30,12 @@ using namespace CalamaresUtils::Units; * Returns an empty QByteArray() on any kind of error. */ STATICTEST QByteArray -logFileContents( qint64 sizeLimitKiB ) +logFileContents( const qint64 sizeLimitBytes ) { - if( sizeLimitKiB == 0 ) - return QByteArray(); + if( sizeLimitBytes != -1 ) + { + cDebug() << "Log upload size limit was limited to" << sizeLimitBytes << "bytes"; + } const QString name = Logger::logFile(); QFile pasteSourceFile( name ); if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) @@ -41,17 +43,18 @@ logFileContents( qint64 sizeLimitKiB ) cWarning() << "Could not open log file" << name; return QByteArray(); } + if( sizeLimitBytes == -1 ) + { + return pasteSourceFile.readAll(); + } QFileInfo fi( pasteSourceFile ); - if( sizeLimitKiB < 0 ) - sizeLimitKiB = 1024; - qint64 sizeLimitBytes = CalamaresUtils::KiBtoBytes( ( unsigned long long ) sizeLimitKiB ); - cDebug() << "Log upload size limit was set to" << sizeLimitKiB << "KiB"; - if ( fi.size() > sizeLimitBytes and sizeLimitBytes > 0 ) + if ( fi.size() > sizeLimitBytes ) { cDebug() << "Only last" << sizeLimitBytes << "bytes of log file (sized" << fi.size() << "bytes) uploaded" ; - pasteSourceFile.seek( fi.size() - sizeLimitBytes + 1_KiB ); + fi.refresh(); + pasteSourceFile.seek( fi.size() - sizeLimitBytes ); } - return pasteSourceFile.read( sizeLimitBytes + 1_KiB ); + return pasteSourceFile.read( sizeLimitBytes ); } @@ -108,7 +111,7 @@ ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* par QString CalamaresUtils::Paste::doLogUpload( QObject* parent ) { - auto [ type, serverUrl, sizeLimitKiB ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimitBytes ] = Calamares::Branding::instance()->uploadServer(); if ( !serverUrl.isValid() ) { cWarning() << "Upload configure with invalid URL"; @@ -120,7 +123,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent ) return QString(); } - QByteArray pasteData = logFileContents( sizeLimitKiB ); + QByteArray pasteData = logFileContents( sizeLimitBytes ); if ( pasteData.isEmpty() ) { // An error has already been logged @@ -172,6 +175,6 @@ CalamaresUtils::Paste::doLogUploadUI( QWidget* parent ) bool CalamaresUtils::Paste::isEnabled() { - auto [ type, serverUrl, sizeLimitKiB ] = Calamares::Branding::instance()->uploadServer(); + auto [ type, serverUrl, sizeLimitBytes ] = Calamares::Branding::instance()->uploadServer(); return type != Calamares::Branding::UploadServerType::None; } diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index 68e972907..84de65cd9 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -16,7 +16,7 @@ #include #include -extern QByteArray logFileContents( qint64 sizeLimitKiB ); +extern QByteArray logFileContents( qint64 sizeLimitBytes ); extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent ); class TestPaste : public QObject From c73e9ec89fa14543bc7ac25f91ee1afde0c5969d Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Thu, 1 Apr 2021 01:05:55 -0600 Subject: [PATCH 6/8] [logUpload] Ran styleScript --- src/libcalamaresui/Branding.cpp | 2 +- src/libcalamaresui/ViewManager.cpp | 6 +++--- src/libcalamaresui/utils/Paste.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 82bd5c5f8..348e99323 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -163,7 +163,7 @@ uploadServerFromMap( const QVariantMap& map ) bool bogus = false; // we don't care about type-name lookup success here return Branding::UploadServerInfo( names.find( typestring, bogus ), QUrl( urlstring, QUrl::ParsingMode::StrictMode ), - ( sizeLimitKiB >=0 ) ? sizeLimitKiB * 1024 : -1 ); + ( sizeLimitKiB >= 0 ) ? sizeLimitKiB * 1024 : -1 ); } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 3a8360e25..c55b5dd67 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -143,9 +143,9 @@ ViewManager::insertViewStep( int before, ViewStep* step ) void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { - bool shouldOfferWebPaste - = std::get<0>(Calamares::Branding::instance()->uploadServer()) != Calamares::Branding::UploadServerType::None - and std::get<2>(Calamares::Branding::instance()->uploadServer()) != 0; + bool shouldOfferWebPaste = std::get< 0 >( Calamares::Branding::instance()->uploadServer() ) + != Calamares::Branding::UploadServerType::None + and std::get< 2 >( Calamares::Branding::instance()->uploadServer() ) != 0; cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index 642b45004..a29d6d362 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -32,9 +32,9 @@ using namespace CalamaresUtils::Units; STATICTEST QByteArray logFileContents( const qint64 sizeLimitBytes ) { - if( sizeLimitBytes != -1 ) + if ( sizeLimitBytes != -1 ) { - cDebug() << "Log upload size limit was limited to" << sizeLimitBytes << "bytes"; + cDebug() << "Log upload size limit was limited to" << sizeLimitBytes << "bytes"; } const QString name = Logger::logFile(); QFile pasteSourceFile( name ); @@ -43,14 +43,14 @@ logFileContents( const qint64 sizeLimitBytes ) cWarning() << "Could not open log file" << name; return QByteArray(); } - if( sizeLimitBytes == -1 ) + if ( sizeLimitBytes == -1 ) { return pasteSourceFile.readAll(); } QFileInfo fi( pasteSourceFile ); if ( fi.size() > sizeLimitBytes ) { - cDebug() << "Only last" << sizeLimitBytes << "bytes of log file (sized" << fi.size() << "bytes) uploaded" ; + cDebug() << "Only last" << sizeLimitBytes << "bytes of log file (sized" << fi.size() << "bytes) uploaded"; fi.refresh(); pasteSourceFile.seek( fi.size() - sizeLimitBytes ); } From b897619558b57d8388a865b33d401678b7f5feff Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Fri, 2 Apr 2021 07:40:03 -0600 Subject: [PATCH 7/8] [logUpload] Added some basic tests --- src/libcalamaresui/Branding.cpp | 8 +++++--- src/libcalamaresui/utils/TestPaste.cpp | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 348e99323..b9445ba83 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -18,6 +18,7 @@ #include "utils/ImageRegistry.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" +#include "utils/Units.h" #include "utils/Yaml.h" #include @@ -161,9 +162,10 @@ uploadServerFromMap( const QVariantMap& map ) } bool bogus = false; // we don't care about type-name lookup success here - return Branding::UploadServerInfo( names.find( typestring, bogus ), - QUrl( urlstring, QUrl::ParsingMode::StrictMode ), - ( sizeLimitKiB >= 0 ) ? sizeLimitKiB * 1024 : -1 ); + return Branding::UploadServerInfo( + names.find( typestring, bogus ), + QUrl( urlstring, QUrl::ParsingMode::StrictMode ), + sizeLimitKiB >= 0 ? CalamaresUtils::KiBtoBytes( static_cast< unsigned long long >( sizeLimitKiB ) ) : -1 ); } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index 84de65cd9..6fea608fe 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -37,14 +37,18 @@ TestPaste::testGetLogFile() { QFile::remove( Logger::logFile() ); // This test assumes nothing **else** has set up logging yet - QByteArray contentsOfLogfileBefore = logFileContents( 16 ); - QVERIFY( contentsOfLogfileBefore.isEmpty() ); + QByteArray logLimitedBefore = logFileContents( 16 ); + QVERIFY( logLimitedBefore.isEmpty() ); + QByteArray logUnlimitedBefore = logFileContents( -1 ); + QVERIFY( logUnlimitedBefore.isEmpty() ); Logger::setupLogLevel( Logger::LOGDEBUG ); Logger::setupLogfile(); - QByteArray contentsOfLogfileAfterSetup = logFileContents( 16 ); - QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() ); + QByteArray logLimitedAfter = logFileContents( 16 ); + QVERIFY( !logLimitedAfter.isEmpty() ); + QByteArray logUnlimitedAfter = logFileContents( -1 ); + QVERIFY( !logUnlimitedAfter.isEmpty() ); } void From 5691f958336849456603fa38f9ff86c9f0bb0e81 Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Fri, 2 Apr 2021 23:50:41 -0600 Subject: [PATCH 8/8] [logUpload] Added one more test --- src/libcalamaresui/utils/TestPaste.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index 6fea608fe..2245c76c4 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -10,6 +10,7 @@ */ #include "Paste.h" +#include "network/Manager.h" #include "utils/Logger.h" @@ -30,6 +31,7 @@ public: private Q_SLOTS: void testGetLogFile(); void testFichePaste(); + void testUploadSize(); }; void @@ -64,7 +66,19 @@ TestPaste::testFichePaste() QVERIFY( !s.isEmpty() ); } +void +TestPaste::testUploadSize() +{ + QByteArray logContent = logFileContents( 100 ); + QString s = ficheLogUpload( logContent, QUrl( "http://termbin.com:9999" ), nullptr ); + QVERIFY( !s.isEmpty() ); + + QUrl url( s ); + QByteArray returnedData = CalamaresUtils::Network::Manager::instance().synchronousGet( url ); + + QCOMPARE( returnedData.size(), 100 ); +} QTEST_GUILESS_MAIN( TestPaste ) #include "utils/moc-warnings.h"