From ab2e5af8d613ec3b324ef47d44221f22313ed579 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 14 Jan 2016 16:05:30 +0000 Subject: [PATCH] refs #545 CAtomicFile::abandon() closes without renaming, and dtor abandons if it is called due to an exception being thrown. --- src/blackmisc/atomicfile.cpp | 5 +++++ src/blackmisc/atomicfile.h | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/atomicfile.cpp b/src/blackmisc/atomicfile.cpp index 7eabdeaca..55d7f2240 100644 --- a/src/blackmisc/atomicfile.cpp +++ b/src/blackmisc/atomicfile.cpp @@ -50,6 +50,11 @@ namespace BlackMisc return error() == NoError; } + void CAtomicFile::abandon() + { + QFile::close(); + } + CAtomicFile::FileError CAtomicFile::error() const { if (m_renameError) { return RenameError; } diff --git a/src/blackmisc/atomicfile.h b/src/blackmisc/atomicfile.h index 03ae71f8f..f99afc710 100644 --- a/src/blackmisc/atomicfile.h +++ b/src/blackmisc/atomicfile.h @@ -30,7 +30,7 @@ namespace BlackMisc CAtomicFile(const QString &filename) : QFile(filename) {} //! \copydoc QFile::~QFile - ~CAtomicFile() { close(); } + ~CAtomicFile() { if (! std::uncaught_exception()) { close(); } } //! \copydoc QFile::open //! Just before opening the file, the filename is changed so we actually write to a temporary file. @@ -43,6 +43,9 @@ namespace BlackMisc //! Calls close() and returns false if there was an error at any stage. bool checkedClose(); + //! Closes the file without renaming it. + void abandon(); + //! \copydoc QFileDevice::error FileError error() const;