refs #545 CAtomicFile::abandon() closes without renaming, and dtor abandons if it is called due to an exception being thrown.

This commit is contained in:
Mathew Sutcliffe
2016-01-14 16:05:30 +00:00
parent f9de444a53
commit ab2e5af8d6
2 changed files with 9 additions and 1 deletions

View File

@@ -50,6 +50,11 @@ namespace BlackMisc
return error() == NoError;
}
void CAtomicFile::abandon()
{
QFile::close();
}
CAtomicFile::FileError CAtomicFile::error() const
{
if (m_renameError) { return RenameError; }

View File

@@ -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;