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 16917 7b725655e48f3251c04be3cdd54cf70bc310f6b8
parent 16916 9b1106f87c8c1c38e2fea32aabc65957a4d95950
child 16918 25b09e25e7de4d1231be92c9456e5b8af4a68ec8
push id1074
push userbugzilla@standard8.plus.com
push dateMon, 03 Feb 2014 22:47:23 +0000
treeherdercomm-beta@6b791b5369ed [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)