[logUpload] Configurable upload size limit
A key 'sizeLimit' added to uploadServer field in branding.desc to limit the size of logFile to upload.
This commit is contained in:
parent
bf7b41f548
commit
6726a926a4
@ -220,13 +220,17 @@ slideshowAPI: 2
|
|||||||
|
|
||||||
|
|
||||||
# These options are to customize online uploading of logs to pastebins:
|
# These options are to customize online uploading of logs to pastebins:
|
||||||
# - type : Defines the kind of pastebin service to be used. Currently
|
# - type : Defines the kind of pastebin service to be used. Currently
|
||||||
# it accepts two values:
|
# it accepts two values:
|
||||||
# - none : disables the pastebin functionality
|
# - none : disables the pastebin functionality
|
||||||
# - fiche : use fiche pastebin server
|
# - fiche : use fiche pastebin server
|
||||||
# - url : Defines the address of pastebin service to be used.
|
# - url : Defines the address of pastebin service to be used.
|
||||||
# Takes string as input. Important bits are the host and port,
|
# Takes string as input. Important bits are the host and port,
|
||||||
# the scheme is not used.
|
# 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 :
|
uploadServer :
|
||||||
type : "fiche"
|
type : "fiche"
|
||||||
url : "http://termbin.com:9999"
|
url : "http://termbin.com:9999"
|
||||||
|
sizeLimit : 20
|
||||||
|
@ -153,15 +153,17 @@ uploadServerFromMap( const QVariantMap& map )
|
|||||||
|
|
||||||
QString typestring = map[ "type" ].toString();
|
QString typestring = map[ "type" ].toString();
|
||||||
QString urlstring = map[ "url" ].toString();
|
QString urlstring = map[ "url" ].toString();
|
||||||
|
qint64 sizeLimit = map[ "sizeLimit" ].toLongLong();
|
||||||
|
|
||||||
if ( typestring.isEmpty() || urlstring.isEmpty() )
|
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
|
bool bogus = false; // we don't care about type-name lookup success here
|
||||||
return Branding::UploadServerInfo( names.find( typestring, bogus ),
|
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
|
/** @brief Load the @p map with strings from @p config
|
||||||
|
@ -226,7 +226,7 @@ public:
|
|||||||
* This is both the type (which may be none, in which case the URL
|
* 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.
|
* 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; }
|
UploadServerInfo uploadServer() const { return m_uploadServer; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,7 +144,7 @@ void
|
|||||||
ViewManager::onInstallationFailed( const QString& message, const QString& details )
|
ViewManager::onInstallationFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
bool shouldOfferWebPaste
|
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;
|
cError() << "Installation failed:" << message;
|
||||||
cDebug() << Logger::SubEntry << "- message:" << message;
|
cDebug() << Logger::SubEntry << "- message:" << message;
|
||||||
|
@ -30,7 +30,7 @@ using namespace CalamaresUtils::Units;
|
|||||||
* Returns an empty QByteArray() on any kind of error.
|
* Returns an empty QByteArray() on any kind of error.
|
||||||
*/
|
*/
|
||||||
STATICTEST QByteArray
|
STATICTEST QByteArray
|
||||||
logFileContents()
|
logFileContents( qint64 sizeLimit )
|
||||||
{
|
{
|
||||||
const QString name = Logger::logFile();
|
const QString name = Logger::logFile();
|
||||||
QFile pasteSourceFile( name );
|
QFile pasteSourceFile( name );
|
||||||
@ -40,11 +40,15 @@ logFileContents()
|
|||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
QFileInfo fi( pasteSourceFile );
|
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
|
QString
|
||||||
CalamaresUtils::Paste::doLogUpload( QObject* parent )
|
CalamaresUtils::Paste::doLogUpload( QObject* parent )
|
||||||
{
|
{
|
||||||
auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer();
|
auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer();
|
||||||
if ( !serverUrl.isValid() )
|
if ( !serverUrl.isValid() )
|
||||||
{
|
{
|
||||||
cWarning() << "Upload configure with invalid URL";
|
cWarning() << "Upload configure with invalid URL";
|
||||||
@ -113,7 +117,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent )
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray pasteData = logFileContents();
|
QByteArray pasteData = logFileContents( sizeLimit );
|
||||||
if ( pasteData.isEmpty() )
|
if ( pasteData.isEmpty() )
|
||||||
{
|
{
|
||||||
// An error has already been logged
|
// An error has already been logged
|
||||||
@ -165,6 +169,6 @@ CalamaresUtils::Paste::doLogUploadUI( QWidget* parent )
|
|||||||
bool
|
bool
|
||||||
CalamaresUtils::Paste::isEnabled()
|
CalamaresUtils::Paste::isEnabled()
|
||||||
{
|
{
|
||||||
auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer();
|
auto [ type, serverUrl, sizeLimit ] = Calamares::Branding::instance()->uploadServer();
|
||||||
return type != Calamares::Branding::UploadServerType::None;
|
return type != Calamares::Branding::UploadServerType::None;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
extern QByteArray logFileContents();
|
extern QByteArray logFileContents( qint64 sizeLimit );
|
||||||
extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent );
|
extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent );
|
||||||
|
|
||||||
class TestPaste : public QObject
|
class TestPaste : public QObject
|
||||||
@ -37,13 +37,13 @@ TestPaste::testGetLogFile()
|
|||||||
{
|
{
|
||||||
QFile::remove( Logger::logFile() );
|
QFile::remove( Logger::logFile() );
|
||||||
// This test assumes nothing **else** has set up logging yet
|
// This test assumes nothing **else** has set up logging yet
|
||||||
QByteArray contentsOfLogfileBefore = logFileContents();
|
QByteArray contentsOfLogfileBefore = logFileContents( 16 );
|
||||||
QVERIFY( contentsOfLogfileBefore.isEmpty() );
|
QVERIFY( contentsOfLogfileBefore.isEmpty() );
|
||||||
|
|
||||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||||
Logger::setupLogfile();
|
Logger::setupLogfile();
|
||||||
|
|
||||||
QByteArray contentsOfLogfileAfterSetup = logFileContents();
|
QByteArray contentsOfLogfileAfterSetup = logFileContents( 16 );
|
||||||
QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() );
|
QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user