Fix: Renaming temp files didn't work on Windows.

Fixes #3216
This commit is contained in:
Gunnar Beutner 2012-10-17 11:35:06 +02:00
parent 69bf01155d
commit e57bf22d82
3 changed files with 22 additions and 2 deletions

View 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);

View 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));
}

View 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));