2009-07-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Make sure that stream is closed before renaming file. Unit test
	fails on mingw32 in the previous implementation.
	* src/CookieStorage.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-07-21 15:19:43 +00:00
parent 1731db1c60
commit 0d1d88257c
2 changed files with 25 additions and 10 deletions

View File

@ -1,3 +1,9 @@
2009-07-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Make sure that stream is closed before renaming file. Unit test
fails on mingw32 in the previous implementation.
* src/CookieStorage.cc
2009-07-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the unit test error without sqlite3

View File

@ -174,19 +174,28 @@ bool CookieStorage::load(const std::string& filename)
bool CookieStorage::saveNsFormat(const std::string& filename)
{
std::string tempfilename = filename+"__temp";
std::ofstream o(tempfilename.c_str(), std::ios::binary);
if(!o) {
_logger->error("Cannot create cookie file %s, cause %s",
filename.c_str(), strerror(errno));
return false;
}
for(std::deque<Cookie>::const_iterator i = _cookies.begin();
i != _cookies.end(); ++i) {
o << (*i).toNsCookieFormat() << "\n";
{
std::ofstream o(tempfilename.c_str(), std::ios::binary);
if(!o) {
_logger->error("Failed to save cookies to %s", filename.c_str());
_logger->error("Cannot create cookie file %s, cause %s",
filename.c_str(), strerror(errno));
return false;
}
for(std::deque<Cookie>::const_iterator i = _cookies.begin();
i != _cookies.end(); ++i) {
o << (*i).toNsCookieFormat() << "\n";
if(!o) {
_logger->error("Failed to save cookies to %s, cause %s",
filename.c_str(), strerror(errno));
return false;
}
}
o.flush();
if(!o) {
_logger->error("Failed to save cookies to %s, cause %s",
filename.c_str(), strerror(errno));
return false;
}
}
if(File(tempfilename).renameTo(filename)) {
return true;