imported patch disable-safe-handling.patch draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Mon, 23 May 2022 03:03:51 +0900
changeset 116834 40437939e4cbdafb714165e2c81ab86bb86bfbf0
parent 116833 be5b008ddbee8ff74196284f43d8476bcc323016
child 116835 3a1ceb1433658fb8d12c5217b62230b81da1fd8a
push id15955
push userishikawa@yk.rim.or.jp
push dateSun, 22 May 2022 18:04:18 +0000
treeherdertry-comm-central@beaacca97fbd [default view] [failures only]
imported patch disable-safe-handling.patch
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgFolderCache.cpp
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/src/nsPop3Protocol.cpp
mailnews/search/src/nsMsgFilterService.cpp
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -2772,19 +2772,26 @@ NS_IMETHODIMP nsMsgAccountManager::LoadV
 NS_IMETHODIMP nsMsgAccountManager::SaveVirtualFolders() {
   if (!m_virtualFoldersLoaded) return NS_OK;
 
   nsCOMPtr<nsIFile> file;
   GetVirtualFoldersFile(file);
 
   // Open a buffered, safe output stream
   nsCOMPtr<nsIOutputStream> outStream;
+#if USE_SAFE_CLOSE
   nsresult rv = MsgNewSafeBufferedFileOutputStream(
       getter_AddRefs(outStream), file, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
       0664);
+#else
+  nsresult rv = MsgNewBufferedFileOutputStream(
+      getter_AddRefs(outStream), file, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
+      0664);
+#endif
+  
   NS_ENSURE_SUCCESS(rv, rv);
 
   WriteLineToOutputStream("version=", "1", outStream);
   for (auto iter = m_incomingServers.Iter(); !iter.Done(); iter.Next()) {
     nsCOMPtr<nsIMsgIncomingServer>& server = iter.Data();
     if (server) {
       nsCOMPtr<nsIMsgFolder> rootFolder;
       server->GetRootFolder(getter_AddRefs(rootFolder));
@@ -2827,25 +2834,36 @@ NS_IMETHODIMP nsMsgAccountManager::SaveV
                   "searchOnline=", searchOnline ? "true" : "false", outStream);
             }
           }
         }
       }
     }
   }
 
+#if USE_SAFE_CLOSE
   nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(outStream, &rv);
   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;
+#else
+  if (outStream) {
+    rv = outStream->Close();
+    if (NS_FAILED(rv)) {
+      NS_WARNING("failed to save personal dictionary file! outStream->Close() failed. possible data loss");
+    }
+  }
+  return rv;
+#endif
+
 }
 
 nsresult nsMsgAccountManager::WriteLineToOutputStream(
     const char* prefix, const char* line, nsIOutputStream* outputStream) {
   uint32_t writeCount;
   outputStream->Write(prefix, strlen(prefix), &writeCount);
   outputStream->Write(line, strlen(line), &writeCount);
   outputStream->Write("\n", 1, &writeCount);
--- a/mailnews/base/src/nsMsgFolderCache.cpp
+++ b/mailnews/base/src/nsMsgFolderCache.cpp
@@ -271,35 +271,53 @@ nsresult nsMsgFolderCache::SaveFolderCac
   Json::StreamWriterBuilder b;
   //  b["indentation"] = "";
   std::string out = Json::writeString(b, *mRoot);
 
   // Safe stream, writes to a tempfile first then moves into proper place when
   // Finish() is called. Could use NS_NewAtomicFileOutputStream, but seems hard
   // to justify a full filesystem flush).
   nsCOMPtr<nsIOutputStream> outputStream;
+#if USE_SAFE_CLOSE
   nsresult rv =
       NS_NewSafeLocalFileOutputStream(getter_AddRefs(outputStream), outFile,
                                       PR_CREATE_FILE | PR_TRUNCATE | PR_WRONLY);
+#else
+  nsresult rv =
+      NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), outFile,
+                                      PR_CREATE_FILE | PR_TRUNCATE | PR_WRONLY);
+#endif
   NS_ENSURE_SUCCESS(rv, rv);
 
   const char* ptr = out.data();
   uint32_t remaining = out.length();
   while (remaining > 0) {
     uint32_t written = 0;
     rv = outputStream->Write(ptr, remaining, &written);
     NS_ENSURE_SUCCESS(rv, rv);
     remaining -= written;
     ptr += written;
   }
+#if USE_SAFE_CLOSE
   nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(outputStream);
   MOZ_ASSERT(safeStream);
   rv = safeStream->Finish();
   NS_ENSURE_SUCCESS(rv, rv);
-
+#else
+  if(outputStream) {
+    rv = outputStream->Close();
+#ifdef DEBUG
+    if(NS_FAILED(rv)) {
+      fprintf(stderr,"outputStream->Close() failed.\n");
+    }
+#endif
+    outputStream = nullptr;             // code uniformity
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+#endif
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgFolderCache::GetCacheElement(
     const nsACString& pathKey, bool createIfMissing,
     nsIMsgFolderCacheElement** result) {
   nsAutoCString key(pathKey);
   if (mRoot->isMember(key.get()) || createIfMissing) {
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -705,16 +705,17 @@ nsMsgBrkMBoxStore::DiscardNewMessage(nsI
   // processing.
   // NS_ENSURE_ARG_POINTER(aOutputStream);
   NS_ENSURE_ARG_POINTER(aNewHdr);
 #ifdef _DEBUG
   PSTREAM2(m_streamOutstandingFolder, "setting to nullptr");
   m_streamOutstandingFolder = nullptr;
 #endif
 
+#ifdef USE_SAFE_CLOSE
   nsCOMPtr<nsISafeOutputStream> safe = do_QueryInterface(aOutputStream);
 
 #if DEBUG
     fprintf(stderr,
             "(debug) nsMsgBrkMBoxStore::DiscardNewMessage safe=%p\n",
             (void *) safe);
 #endif
 
@@ -725,16 +726,18 @@ nsMsgBrkMBoxStore::DiscardNewMessage(nsI
 #ifdef DEBUG
     fprintf(stderr,
             "(debug) nsMsgBrkMBoxStore::DiscardNewMessage calls "
             "aOutputStream->Close() = 0x%" PRIx32 "\n",
             static_cast<uint32_t>(rv));
 #endif
     return rv;
   }
+#endif // USE_SAFE_CLOSE
+  
   // Truncate the mbox back to where we started writing.
   uint64_t hdrOffset;
   aNewHdr->GetMessageOffset(&hdrOffset);
   CLOSESTREAM2(aOutputStream, "before Close()");
   rv = aOutputStream->Close();
 #ifdef DEBUG
   fprintf(stderr,
           "(debug) nsMsgBrkMBoxStore::DiscardNewMessage calls, "
@@ -759,43 +762,49 @@ nsMsgBrkMBoxStore::FinishNewMessage(nsIO
   nsresult rv = NS_OK;
 
   // NS_ENSURE_ARG_POINTER(aOutputStream);
 #ifdef _DEBUG
   PSTREAM2(m_streamOutStandingFolder, "setting to nullptr");
   // Do we need this?
   m_streamOutstandingFolder = nullptr;
 #endif
+
+#ifdef USE_SAFE_CLOSE 
   // Quarantining is implemented using a nsISafeOutputStream.
   // It requires an explicit commit, or the data will be discarded.
   nsCOMPtr<nsISafeOutputStream> safe = do_QueryInterface(aOutputStream);
   CLOSESTREAM2(aOutputStream, "before possible Close() via safe");
   if (safe) {
     rv = safe->Finish();
 #if DEBUG
     fprintf(stderr,
             "{deubg} nsMsgBrkMBoxStore::FinishNewMessage "
             "safe->Finish() = 0x%" PRIx32 "\n",
             static_cast<uint32_t>(rv));
 #endif
 
-#if 0 
-    // Isn't ->Close() necessary?
-    // No, one too many 
     nsresult rv2 = aOutputStream->Close();
     fprintf(stderr,
             "{deubg} nsMsgBrkMBoxStore::FinishNewMessage "
             "aOutputStream->Close() = 0x%" PRIx32 "\n",
             static_cast<uint32_t>(rv2));
-#endif
-
     return rv;
 
   }
   return NS_OK;
+#else
+  nsresult rv2 = aOutputStream->Close();
+  fprintf(stderr,
+          "{deubg} nsMsgBrkMBoxStore::FinishNewMessage "
+          "aOutputStream->Close() = 0x%" PRIx32 "\n",
+          static_cast<uint32_t>(rv2));
+  return rv;
+#endif
+
 }
 
 NS_IMETHODIMP
 nsMsgBrkMBoxStore::MoveNewlyDownloadedMessage(nsIMsgDBHdr* aNewHdr,
                                               nsIMsgFolder* aDestFolder,
                                               bool* aResult) {
   NS_ENSURE_ARG_POINTER(aNewHdr);
   NS_ENSURE_ARG_POINTER(aDestFolder);
@@ -1035,17 +1044,17 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::ChangeF
 
   if (NS_FAILED(rv1)) {
     NS_WARNING("Flush after updateFolderFlag loop failed");
   }
 
   if (restoreStreamPos != -1)
     seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, restoreStreamPos);
   else if (outputStream) {
-    PSTREAM2(outFileStream, "before close in ChangeFlags");
+    PSTREAM2(outputStream, "before close in ChangeFlags");
     nsresult rv3 = outputStream->Close();
     if (NS_FAILED(rv3)) NS_WARNING("outputStream->Close() failed;");
     outputStream = nullptr;  // code uniformity.
   }
 
   SetDBValid(aHdrArray[0]);
   return NS_OK;
 }
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -305,18 +305,23 @@ static void net_pop3_write_state(Pop3Uid
   int32_t len = 0;
   nsCOMPtr<nsIFile> popState;
 
   mailDirectory->Clone(getter_AddRefs(popState));
   if (!popState) return;
   popState->AppendNative("popstate.dat"_ns);
 
   nsCOMPtr<nsIOutputStream> fileOutputStream;
+#ifdef USE_SAFE_CLOSE
   nsresult rv = MsgNewSafeBufferedFileOutputStream(
       getter_AddRefs(fileOutputStream), popState, -1, 00600);
+#else
+  nsresult rv = MsgNewBufferedFileOutputStream(
+      getter_AddRefs(fileOutputStream), popState, -1, 00600);
+#endif
   if (NS_FAILED(rv)) return;
 
   const char tmpBuffer[] =
       "# POP3 State File" MSG_LINEBREAK
       "# This is a generated file!  Do not edit." MSG_LINEBREAK MSG_LINEBREAK;
 
   uint32_t numBytesWritten;
   nsresult rv4 =
@@ -344,25 +349,37 @@ static void net_pop3_write_state(Pop3Uid
       fileOutputStream->Write(" ", 1, &numBytesWritten);
       fileOutputStream->Write(host->user, strlen(host->user), &numBytesWritten);
       fileOutputStream->Write(MSG_LINEBREAK, MSG_LINEBREAK_LEN,
                               &numBytesWritten);
       PL_HashTableEnumerateEntries(host->hash, net_pop3_write_mapper,
                                    (void*)fileOutputStream);
     }
   }
+#ifdef USE_SAFE_CLOSE
   nsCOMPtr<nsISafeOutputStream> safeStream =
       do_QueryInterface(fileOutputStream);
   NS_ASSERTION(safeStream, "expected a safe output stream!");
   if (safeStream) {
     rv = safeStream->Finish();
     if (NS_FAILED(rv)) {
       NS_WARNING("failed to save pop state! possible data loss");
     }
   }
+#else
+
+  /*
+   * So how do we tell that we have failed if this is void and not
+   * returning an error code?
+   */
+  rv = fileOutputStream->Close();
+  if (NS_FAILED(rv)) {
+    NS_WARNING("failed to save pop state! Close() failed.  possible data loss");
+  }
+#endif
 }
 
 static void net_pop3_free_state(Pop3UidlHost* host) {
   Pop3UidlHost* h;
   while (host) {
     h = host->next;
     PR_Free(host->host);
     PR_Free(host->user);
--- a/mailnews/search/src/nsMsgFilterService.cpp
+++ b/mailnews/search/src/nsMsgFilterService.cpp
@@ -210,31 +210,49 @@ NS_IMETHODIMP nsMsgFilterService::SaveFi
   NS_ENSURE_ARG_POINTER(filterList);
 
   nsCString listId;
   filterList->GetListId(listId);
   MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
           ("Saving filter list %s", listId.get()));
 
   nsCOMPtr<nsIOutputStream> strm;
+#if USE_SAFE_CLOSE
   nsresult rv = MsgNewSafeBufferedFileOutputStream(getter_AddRefs(strm),
                                                    filterFile, -1, 0600);
+#else
+  nsresult rv = MsgNewBufferedFileOutputStream(getter_AddRefs(strm),
+                                                   filterFile, -1, 0600);
+#endif
+
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = filterList->SaveToFile(strm);
-
+  // ??? we are not checking the return value above?
+#if USE_SAFE_CLOSE
   nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(strm);
   NS_ASSERTION(safeStream, "expected a safe output stream!");
   if (safeStream) {
     rv = safeStream->Finish();
     if (NS_FAILED(rv)) {
       NS_WARNING("failed to save filter file! possible data loss");
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Error, ("Save of list failed"));
     }
   }
+#else
+  if (strm) {
+    rv = strm->Close();
+    if (NS_FAILED(rv)) {
+      NS_WARNING("failed to save filter file! strm->Close() failed.  possible data loss");
+      MOZ_LOG(FILTERLOGMODULE, LogLevel::Error, ("Save of list failed"));
+      return rv;                        // this seems correct thing to do.
+    }
+  }
+#endif
+
   return rv;
 }
 
 NS_IMETHODIMP nsMsgFilterService::CancelFilterList(
     nsIMsgFilterList* filterList) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }