]> granicus.if.org Git - icinga2/commitdiff
Fix: Renaming temp files didn't work on Windows.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Oct 2012 09:35:06 +0000 (11:35 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Oct 2012 09:35:06 +0000 (11:35 +0200)
Fixes #3216

components/compat/compatcomponent.cpp
lib/base/dynamicobject.cpp
lib/base/object.cpp

index 38ec74fe31f4a92cdb41afa60a7efca264b95cf5..45bd28f64308adf42d8a2542ebbbe4e94f7ebd03 100644 (file)
@@ -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);
index 9ee0f296051e92ad6d5cef19cb6d5a61412b5489..7e983cdb87353f8c77cd7d1b98a497596d5975ce 100644 (file)
@@ -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));
 }
index d0e221f4eb9d18935619ca90a15cb331f7711cf8..a0f7d03d2ed3e5c9578f0549ab9ee7f90a9be555 100644 (file)
@@ -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));