From 96404275ed7855bd23b747fcb9b9a184e293c4da Mon Sep 17 00:00:00 2001 From: upstream svn Date: Tue, 4 Oct 2011 19:29:38 +0000 Subject: [PATCH] Fixed problem in the CFile write_safe concept If there is an exception during writing (like disk full), ~CFile() is still called. So don't rename and replace the original file when Close() is called from the dtor - this would defeat the whole concept! As consequence Close() has always to be called for files opened with write_safe. --- .svn-revision | 2 +- src/CFile.cpp | 4 ++++ src/CFile.h | 1 + src/KnownFileList.cpp | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.svn-revision b/.svn-revision index 9bf39221..624bcd1a 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10620 +10621 diff --git a/src/CFile.cpp b/src/CFile.cpp index 948ff8a3..db6e82a2 100644 --- a/src/CFile.cpp +++ b/src/CFile.cpp @@ -169,6 +169,10 @@ CFile::CFile(const wxString& fileName, OpenMode mode) CFile::~CFile() { if (IsOpened()) { + // If the writing gets aborted, dtor is still called. + // In this case do NOT replace the original file with the + // probably broken new one! + m_safeWrite = false; Close(); } } diff --git a/src/CFile.h b/src/CFile.h index 631f97c3..8ca05db7 100644 --- a/src/CFile.h +++ b/src/CFile.h @@ -88,6 +88,7 @@ public: * Calling Open with the openmode 'write_safe' will append ".new" * to the file name and otherwise work like 'write'. * On close it will be renamed to the original name. + * Close() has to be called manually - destruct won't rename the file! * * If an accessMode is not explicitly specified, the accessmode * specified via CPreferences::GetFilePermissions will be used. diff --git a/src/KnownFileList.cpp b/src/KnownFileList.cpp index 0d2c199e..88046736 100644 --- a/src/KnownFileList.cpp +++ b/src/KnownFileList.cpp @@ -159,6 +159,7 @@ void CKnownFileList::Save() file.Seek(0); file.WriteUInt8(bContainsAnyLargeFiles ? MET_HEADER_WITH_LARGEFILES : MET_HEADER); + file.Close(); } catch (const CIOFailureException& e) { AddLogLineC(CFormat(_("Error while saving %s file: %s")) % m_filename % e.what()); } -- 2.11.4.GIT