summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorFrerich Raabe <raabe@froglogic.com>2015-11-23 23:44:39 +0100
committerKatja Marttila <katja.marttila@theqtcompany.com>2016-02-15 05:47:14 +0000
commitdd24111989653ec43275cc1992e633b5ec46612b (patch)
tree2222822951a6fdaae960550016edfaff8cf31893 /src/libs
parent264183e9be4f6a4a23771156a5d4257a23b1aa28 (diff)
Factored flushing of VerboseWriter into dedicated method
This patch introduces a (yet unused) VerboseWriter::flush() method which can be used to explicitly trigger flushing the installation log. This permits clients to decide when to do the flushing instead of having to rely on the destructor being called. The destructor will call flush() if needed - whether flushing is needed is defined in terms of the 'perFileBuffer': if it's open, flushing is needed - otherwise, no flushing is needed. Change-Id: I17f1df96e5ddf3b6f613d647c28b90b6973c9393 Reviewed-by: Katja Marttila <katja.marttila@theqtcompany.com>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/utils.cpp17
-rw-r--r--src/libs/installer/utils.h2
2 files changed, 16 insertions, 3 deletions
diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp
index 8c19e8731..7e563a284 100644
--- a/src/libs/installer/utils.cpp
+++ b/src/libs/installer/utils.cpp
@@ -219,12 +219,20 @@ QInstaller::VerboseWriter::VerboseWriter()
QInstaller::VerboseWriter::~VerboseWriter()
{
+ if (preFileBuffer.isOpen())
+ (void)flush();
+}
+
+bool QInstaller::VerboseWriter::flush()
+{
stream.flush();
if (logFileName.isEmpty()) // binarycreator
- return;
+ return true;
+ if (!preFileBuffer.isOpen())
+ return true;
//if the installer installed nothing - there is no target directory - where the logfile can be saved
if (!QFileInfo(logFileName).absoluteDir().exists())
- return;
+ return true;
QFile output(logFileName);
if (output.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text)) {
@@ -235,8 +243,11 @@ QInstaller::VerboseWriter::~VerboseWriter()
output.write(logInfo.toLocal8Bit());
output.write(preFileBuffer.data());
output.close();
+ preFileBuffer.close();
+ stream.setDevice(0);
+ return true;
}
- stream.setDevice(0);
+ return false;
}
void QInstaller::VerboseWriter::setFileName(const QString &fileName)
diff --git a/src/libs/installer/utils.h b/src/libs/installer/utils.h
index cf7220106..55ec2009e 100644
--- a/src/libs/installer/utils.h
+++ b/src/libs/installer/utils.h
@@ -81,6 +81,8 @@ namespace QInstaller {
static VerboseWriter *instance();
+ bool flush();
+
void appendLine(const QString &msg);
void setFileName(const QString &fileName);