--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -583,16 +583,19 @@ nsMsgBrkMBoxStore::GetNewMsgOutputStream
nsCOMPtr<nsIOutputStream> mboxStream;
nsresult rv = InternalGetNewMsgOutputStream(aFolder, aNewMsgHdr,
getter_AddRefs(mboxStream));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<nsQuarantinedOutputStream> qStream =
new nsQuarantinedOutputStream(mboxStream);
qStream.forget(aResult);
+
+ *aResult = mboxStream; // missing ???
+
return NS_OK;
}
nsresult nsMsgBrkMBoxStore::InternalGetNewMsgOutputStream(
nsIMsgFolder* aFolder, nsIMsgDBHdr** aNewMsgHdr,
nsIOutputStream** aResult) {
NS_ENSURE_ARG_POINTER(aFolder);
NS_ENSURE_ARG_POINTER(aNewMsgHdr);
@@ -601,44 +604,68 @@ nsresult nsMsgBrkMBoxStore::InternalGetN
#ifdef _DEBUG
NS_ASSERTION(m_streamOutstandingFolder != aFolder, "didn't finish prev msg");
m_streamOutstandingFolder = aFolder;
#endif
nsresult rv;
nsCOMPtr<nsIFile> mboxFile;
rv = aFolder->GetFilePath(getter_AddRefs(mboxFile));
+#ifdef DEBUG
+ fprintf(stderr,"{debug} GetFilePath failed in InternalGetNewMsgOutputStream. rv=0x%"
+ PRIx32 "\n",
+ static_cast<uint32_t>(rv));
+#endif
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMsgDatabase> db;
aFolder->GetMsgDatabase(getter_AddRefs(db));
if (!db && !*aNewMsgHdr) NS_WARNING("no db, and no message header");
bool exists = false;
mboxFile->Exists(&exists);
if (!exists) {
rv = mboxFile->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
+#ifdef DEBUG
+ fprintf(stderr,"{debug} mboxFile->Createfailed in InternalGetNewMsgOutputStream. rv=0x%"
+ PRIx32 "\n",
+ static_cast<uint32_t>(rv));
+#endif
NS_ENSURE_SUCCESS(rv, rv);
+ } else {
+#ifdef DEBUG
+ fprintf(stderr,"{debug} mboxFile existed and so did not create.\n");
+#endif
}
nsCString URI;
aFolder->GetURI(URI);
nsCOMPtr<nsISeekableStream> seekable;
- // Note here, m_outputStreams is a hash table (maybe an array) or something
+ // Note here, m_outputStreams (note the plural) is a hash table (maybe an array) or something
// like that in this part of code.
if (m_outputStreams.Get(URI, aResult)) {
seekable = do_QueryInterface(*aResult, &rv);
+#ifdef DEBUG
+ fprintf(stderr,"{debug} do_QueryIntgerface(*aResult, &rv) failed in InternalGetNewMsgOutputStream. rv=0x%"
+ PRIx32 "\n",
+ static_cast<uint32_t>(rv));
+#endif
NS_ENSURE_SUCCESS(rv, rv);
rv = seekable->Seek(nsISeekableStream::NS_SEEK_END, 0);
if (NS_FAILED(rv)) {
+#ifdef DEBUG
+ fprintf(stderr,"{debug} seekable->Seek() to end InternalGetNewMsgOutputStream rv=0x%"
+ PRIx32 ", and m_outputSterams.Remoe(URI=%s)\n",
+ static_cast<uint32_t>(rv), URI.get());
+#endif
m_outputStreams.Remove(URI);
NS_RELEASE(*aResult);
}
}
- if (!*aResult) {
+ if (!*aResult) { // Is there case we pass a nullptg here?
PSTREAM2(mboxFile,
"mboxFile being passed to MsgNewBufferedFileOutputStream(): I "
"suspect this is nil under certain circumstances.");
rv = MsgNewBufferedFileOutputStream(aResult, mboxFile, PR_WRONLY, 00600);
#ifdef DEBUG
// print pathname for easy analysis of the log on tryserver.
nsAutoCString mboxFilePath;
// GetNativePath is not available under Windows.
@@ -668,25 +695,62 @@ nsresult nsMsgBrkMBoxStore::InternalGetN
"rv=0x%" PRIx32 "\n",
static_cast<uint32_t>(rv));
}
#endif
NS_ASSERTION(NS_SUCCEEDED(rv), "failed opening offline store for output");
if (NS_FAILED(rv))
printf("failed opening offline store for %s\n", URI.get());
NS_ENSURE_SUCCESS(rv, rv);
+ PSTREAM2(*aResult,
+ "*aResult being returned after MsgNewBufferedFileOutputStream. Is it seekable?\n");
seekable = do_QueryInterface(*aResult, &rv);
+#ifdef DEBUG
+ if(NS_FAILED(rv)) {
+ fprintf(stderr,"{debug} do_QueryIntgerface(*aResult, &rv) failed in InternalGetNewMsgOutputStream. rv=0x%"
+ PRIx32 " at line=%d\n",
+ static_cast<uint32_t>(rv), __LINE__);
+ }
+#endif
NS_ENSURE_SUCCESS(rv, rv);
+
rv = seekable->Seek(nsISeekableStream::NS_SEEK_END, 0);
+#ifdef DEBUG
+ if(NS_FAILED(rv)) {
+ fprintf(stderr,"{debug} seekable->Seek to the end failed in InternalGetNewMsgOutputStream. rv=0x%"
+ PRIx32 " at line=%d\n",
+ static_cast<uint32_t>(rv), __LINE__);
+ }
+#endif
NS_ENSURE_SUCCESS(rv, rv);
+ // We have registered URI and *aResult pair in m_outputStreams.
m_outputStreams.InsertOrUpdate(URI, *aResult);
+#ifdef DEBUG
+ fprintf(stderr,"{debu}: we have registered (%p, URI=%s) in m_outputStreams\n",
+ (void *) *aResult, URI.get());
+#endif
+
}
+#ifdef DEBUG
+ else {
+ fprintf(stderr,
+ "{debug} *aResult was NOT null and else [do nothing] was taken in InternalGetNewMsgOutputStream.\n");
+ }
+#endif
int64_t filePos;
- seekable->Tell(&filePos);
-
+ // This tell can fail with remote file system during transient network errors, etc. :-(
+ // This error |rv| will be returned.
+ rv = seekable->Tell(&filePos);
+#ifdef DEBUG
+ if (NS_FAILED(rv)) {
+ fprintf(stderr,
+ "(debug) seekable->Tell failed. rv=0x%" PRIx32 "\n",
+ static_cast<uint32_t>(rv));
+ }
+#endif
if (db && !*aNewMsgHdr) {
db->CreateNewHdr(nsMsgKey_None, aNewMsgHdr);
}
if (*aNewMsgHdr) {
char storeToken[100];
PR_snprintf(storeToken, sizeof(storeToken), "%lld", filePos);
(*aNewMsgHdr)->SetMessageOffset(filePos);