From c1aa0b581e159fe31fb305f49002cdd9a3478ca4 Mon Sep 17 00:00:00 2001 From: Anubhav Choudhary Date: Thu, 1 Apr 2021 00:25:37 -0600 Subject: [PATCH] [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