Bug 912465 - Use MsgNewSafeBufferedFileOutputStream instead of NewLocalFileOutputStream in nsMsgAccountManager.cpp. r=irving
authorJohannes Buchner <buchner.johannes@gmx.at>
Thu, 21 Nov 2013 09:02:24 -0500
changeset 13299 7b725655e48f
parent 13298 9b1106f87c8c
child 13300 25b09e25e7de
push id9665
push userryanvm@gmail.com
push dateThu, 21 Nov 2013 14:03:18 +0000
treeherdercomm-central@d7853d9e9971 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersirving
bugs912465
Bug 912465 - Use MsgNewSafeBufferedFileOutputStream instead of NewLocalFileOutputStream in nsMsgAccountManager.cpp. r=irving
mailnews/base/src/nsMsgAccountManager.cpp
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -3121,33 +3121,35 @@ NS_IMETHODIMP nsMsgAccountManager::SaveV
 {
   if (!m_virtualFoldersLoaded)
     return NS_OK;
 
   nsCOMPtr<nsIFile> file;
   GetVirtualFoldersFile(file);
 
   // Open a buffered, safe output stream
-  nsCOMPtr<nsIOutputStream> outStreamSink;
-  nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStreamSink),
-                                                file,
-                                                PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
-                                                0664);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIOutputStream> outStream;
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(outStream), outStreamSink, 4096);
+  nsresult rv = MsgNewSafeBufferedFileOutputStream(getter_AddRefs(outStream),
+                                                   file,
+                                                   PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
+                                                   0664);
   NS_ENSURE_SUCCESS(rv, rv);
 
   WriteLineToOutputStream("version=", "1", outStream);
   m_incomingServers.Enumerate(saveVirtualFolders, &outStream);
 
   nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(outStream, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-  return safeStream->Finish();
+  NS_ASSERTION(safeStream, "expected a safe output stream!");
+  if (safeStream) {
+    rv = safeStream->Finish();
+    if (NS_FAILED(rv)) {
+      NS_WARNING("failed to save personal dictionary file! possible data loss");
+    }
+  }
+  return rv;
 }
 
 PLDHashOperator
 nsMsgAccountManager::saveVirtualFolders(nsCStringHashKey::KeyType key,
                                         nsCOMPtr<nsIMsgIncomingServer>& server,
                                         void *data)
 {
   if (server)