check whether removing tell was OK. draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Mon, 23 May 2022 03:03:50 +0900
changeset 116816 1dfd6ed81aacad47adc3d55626864fb1cf2b87ac
parent 116815 2fb240c10bf3ac417acce2f7c9694eb9c535bf1b
child 116817 804b8f3dbcf263e514b7f487e91e5d2314710cbf
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]
check whether removing tell was OK.
mailnews/local/src/nsLocalMailFolder.cpp
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1929,16 +1929,45 @@ nsresult nsMsgLocalMailFolder::InitCopyM
 // nsICopyMessageListener
 NS_IMETHODIMP nsMsgLocalMailFolder::BeginCopy() {
   if (!mCopyState) return NS_ERROR_NULL_POINTER;
 
   if (!mCopyState->m_copyingMultipleMessages) {
     nsresult rv = InitCopyMsgHdrAndFileStream();
     NS_ENSURE_SUCCESS(rv, rv);
   }
+
+  // bug 1719996 check. file position should not change before/after seek
+  {
+    if (mCopyState->m_fileStream) {
+      nsresult rv;
+      nsCOMPtr<nsISeekableStream> seekableStream =
+        do_QueryInterface(mCopyState->m_fileStream, &rv);
+      if(NS_SUCCEEDED(rv) && seekableStream) {
+        int64_t filepos1 = -1;
+        int64_t filepos2 = -1;
+        // I am checking the filepos1, filepos2 values.
+        // I should check Seek return value.
+        seekableStream->Tell(&filepos1);
+        seekableStream->Seek(nsISeekableStream::NS_SEEK_END, 0);
+        seekableStream->Tell(&filepos2);
+        // compare, they should match.
+        if (!(filepos1 == filepos2 && filepos1 != -1)) {
+          fprintf(stderr, "{debug} filepostion was wrong: filepos1 = %" PRIu64
+                  " filepos2 = %" PRIu64 "\n",
+                  filepos1, filepos2);
+        }
+        NS_ASSERTION(filepos1 == filepos2 && filepos1 != -1, "fileposition was not at the EOF!");
+      } else {
+        fprintf(stderr, "{debug} %s:%c - conversion to seekable stream failed.\n",
+                __FILE__, __LINE__);
+      }
+    }
+  }
+
   // The output stream may or may not be set already, depending upon all kinds
   // of inscrutable conditions. This needs cleaning up (see Bug 1731177).
   if (!mCopyState->m_fileStream) {
     return NS_OK;
   }
 
   int32_t messageIndex = (mCopyState->m_copyingMultipleMessages)
                              ? mCopyState->m_curCopyIndex - 1
@@ -1986,16 +2015,18 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Copy
     char* newBuffer = (char*)PR_REALLOC(mCopyState->m_dataBuffer,
                                         aLength + mCopyState->m_leftOver + 4);
     if (!newBuffer) return NS_ERROR_OUT_OF_MEMORY;
 
     mCopyState->m_dataBuffer = newBuffer;
     mCopyState->m_dataBufferSize = aLength + mCopyState->m_leftOver + 3;
   }
 
+
+
   rv = aIStream->Read(mCopyState->m_dataBuffer + mCopyState->m_leftOver + 1,
                       aLength, &readCount);
   NS_ENSURE_SUCCESS(rv, rv);
   mCopyState->m_leftOver += readCount;
   mCopyState->m_dataBuffer[mCopyState->m_leftOver + 1] = '\0';
   char* start = mCopyState->m_dataBuffer + 1;
   char* endBuffer = mCopyState->m_dataBuffer + mCopyState->m_leftOver + 1;
 
@@ -2161,16 +2192,44 @@ nsMsgLocalMailFolder::EndCopy(bool aCopy
   // cases, this is done in EndMessage, while in others it is done here in
   // EndCopy. When we do the close in EndMessage, we'll set
   // mCopyState->m_fileStream to null since it is no longer needed, and detect
   // here the null stream so we know that we don't have to close it here.
   //
   // Similarly, m_parseMsgState->GetNewMsgHdr() returns a null hdr if the hdr
   // has already been processed by EndMessage so it is not doubly added here.
 
+  // bug 1719996 check. file position should not change before/after seek
+  {
+    if (mCopyState->m_fileStream) {
+      nsresult rv;
+      nsCOMPtr<nsISeekableStream> seekableStream =
+        do_QueryInterface(mCopyState->m_fileStream, &rv);
+      if(NS_SUCCEEDED(rv) && seekableStream) {
+        int64_t filepos1 = -1;
+        int64_t filepos2 = -1;
+        // I am checking the filepos1, filepos2 values.
+        // I should check Seek return value.
+        seekableStream->Tell(&filepos1);
+        seekableStream->Seek(nsISeekableStream::NS_SEEK_END, 0);
+        seekableStream->Tell(&filepos2);
+        // compare, they should match.
+        if (!(filepos1 == filepos2 && filepos1 != -1)) {
+          fprintf(stderr, "{debug} filepostion was wrong: filepos1 = %" PRIu64
+                  " filepos2 = %" PRIu64 "\n",
+                  filepos1, filepos2);
+        }
+        NS_ASSERTION(filepos1 == filepos2 && filepos1 != -1, "fileposition was not at the EOF!");
+      } else {
+        fprintf(stderr, "{debug} %s:%c - conversion to seekable stream failed.\n",
+                __FILE__, __LINE__);
+      }
+    }
+  }
+
   if (mCopyState->m_fileStream) {
     rv = FinishNewLocalMessage(mCopyState->m_fileStream, mCopyState->m_newHdr,
                                mCopyState->m_msgStore,
                                mCopyState->m_parseMsgState);
     if (NS_SUCCEEDED(rv) && mCopyState->m_newHdr)
       mCopyState->m_newHdr->GetMessageKey(&mCopyState->m_curDstKey);
     if (multipleCopiesFinished)
       mCopyState->m_fileStream->Close();