[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
@ -227,6 +227,10 @@ 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.
|
||||
uploadServer :
|
||||
type : "fiche"
|
||||
url : "http://termbin.com:9999"
|
||||
sizeLimit : 20
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
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() );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user