[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
This commit is contained in:
parent
b42f86f20f
commit
c1aa0b581e
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user