From a740d5286157c3aa79eaa0d3cbb8484e518b0213 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 7 Feb 2017 13:44:33 +0200 Subject: [PATCH] Fix bug. QTemporaryFile blocks a file on Windows. --HG-- branch : develop --- src/libs/ifc/xml/vabstractconverter.cpp | 42 ++++++++++++------------- src/libs/ifc/xml/vabstractconverter.h | 6 ++-- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index 4fa5dd5cf..9b6e2bde4 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -84,7 +84,6 @@ QString VAbstractConverter::Convert() const QString errorMsg(tr("Error openning a temp file file: %1.").arg(m_tmpFile.errorString())); throw VException(errorMsg); } - m_tmpFile.close(); m_ver < MaxVer() ? ApplyPatches() : DowngradeToCurrentMaxVersion(); @@ -256,23 +255,6 @@ Q_NORETURN void VAbstractConverter::InvalidVersion(int ver) const throw VException(errorMsg); } -//--------------------------------------------------------------------------------------------------------------------- -bool VAbstractConverter::SaveDocument(const QString &fileName, QString &error) const -{ - try - { - TestUniqueId(); - } - catch (const VExceptionWrongId &e) - { - Q_UNUSED(e) - error = tr("Error no unique id."); - return false; - } - - return VDomDocument::SaveDocument(fileName, error); -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractConverter::ValidateInputFile(const QString ¤tSchema) const { @@ -311,12 +293,28 @@ void VAbstractConverter::ValidateInputFile(const QString ¤tSchema) const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractConverter::Save() const +void VAbstractConverter::Save() { - QString error; - if (SaveDocument(m_convertedFileName, error) == false) + try { - VException e(error); + TestUniqueId(); + } + catch (const VExceptionWrongId &e) + { + Q_UNUSED(e) + VException ex(tr("Error no unique id.")); + throw ex; + } + + m_tmpFile.resize(0);//clear previous content + const int indent = 4; + QTextStream out(&m_tmpFile); + out.setCodec("UTF-8"); + save(out, indent); + + if (not m_tmpFile.flush()) + { + VException e(m_tmpFile.errorString()); throw e; } } diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 1943c3638..8872b7f1c 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -53,8 +53,7 @@ public: explicit VAbstractConverter(const QString &fileName); virtual ~VAbstractConverter() Q_DECL_OVERRIDE; - QString Convert(); - virtual bool SaveDocument(const QString &fileName, QString &error) const Q_DECL_OVERRIDE; + QString Convert(); static int GetVersion(const QString &version); @@ -62,10 +61,9 @@ protected: int m_ver; QString m_convertedFileName; - void ValidateInputFile(const QString ¤tSchema) const; Q_NORETURN void InvalidVersion(int ver) const; - void Save() const; + void Save(); void SetVersion(const QString &version); virtual int MinVer() const =0;