From 5c588352d9739c4632980996b352781f3c1620ee Mon Sep 17 00:00:00 2001 From: psychon Date: Thu, 28 Aug 2008 18:50:42 +0000 Subject: [PATCH] WriteToDisk() didn't make sure the file was empty when its map was empty This bug was introduced by SilverLeo who also found and fixed it. :P git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1176 726aef4b-f618-498e-8847-2d620e286838 --- String.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/String.cpp b/String.cpp index 83b12208..e9224cd0 100644 --- a/String.cpp +++ b/String.cpp @@ -1001,10 +1001,15 @@ bool CString::RightChomp(unsigned int uLen) { //////////////// MCString //////////////// int MCString::WriteToDisk(const CString& sPath, mode_t iMode) { - if (this->empty()) - return MCS_SUCCESS; - CFile cFile(sPath); + + if (this->empty()) { + if (!cFile.Exists()) + return MCS_SUCCESS; + if (cFile.Delete()) + return MCS_SUCCESS; + } + if (!cFile.Open(O_WRONLY|O_CREAT|O_TRUNC, iMode)) { return MCS_EOPEN; }