From e57bf22d82355efa886fd1030faa8c1c3d269e09 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 17 Oct 2012 11:35:06 +0200 Subject: [PATCH] Fix: Renaming temp files didn't work on Windows. Fixes #3216 --- components/compat/compatcomponent.cpp | 14 ++++++++++++-- lib/base/dynamicobject.cpp | 6 ++++++ lib/base/object.cpp | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 38ec74fe3..45bd28f64 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -340,10 +340,20 @@ void CompatComponent::StatusTimerHandler(void) } statusfp.close(); - rename(statuspathtmp.CStr(), statuspath.CStr()); + objectfp.close(); + +#ifdef _WIN32 + _unlink(statuspath.CStr()); + _unlink(objectspath.CStr()); +#endif /* _WIN32 */ + + statusfp.close(); + if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0) + throw_exception(PosixException("rename() failed", errno)); objectfp.close(); - rename(objectspathtmp.CStr(), objectspath.CStr()); + if (rename(objectspathtmp.CStr(), objectspath.CStr()) < 0) + throw_exception(PosixException("rename() failed", errno)); } EXPORT_COMPONENT(compat, CompatComponent); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 9ee0f2960..7e983cdb8 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -416,6 +416,12 @@ void DynamicObject::DumpObjects(const String& filename) } } + fp.close(); + +#ifdef _WIN32 + _unlink(filename.CStr()); +#endif /* _WIN32 */ + if (rename(tempFilename.CStr(), filename.CStr()) < 0) throw_exception(PosixException("rename() failed", errno)); } diff --git a/lib/base/object.cpp b/lib/base/object.cpp index d0e221f4e..a0f7d03d2 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -116,6 +116,10 @@ void Object::PrintMemoryProfile(void) } } +#ifdef _WIN32 + _unlink("dictionaries.dump"); +#endif /* _WIN32 */ + dictfp.close(); if (rename("dictionaries.dump.tmp", "dictionaries.dump") < 0) throw_exception(PosixException("rename() failed", errno));