Explorar el Código

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
Tatsuhiro Tsujikawa hace 16 años
padre
commit
0d1d88257c
Se han modificado 2 ficheros con 25 adiciones y 10 borrados
  1. 6 0
      ChangeLog
  2. 19 10
      src/CookieStorage.cc

+ 6 - 0
ChangeLog

@@ -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

+ 19 - 10
src/CookieStorage.cc

@@ -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;