Bug 912465 - Use MsgNewSafeBufferedFileOutputStream instead of NewLocalFileOutputStream in various places. r=ehsan

This commit is contained in:
Johannes Buchner 2013-11-19 09:13:44 -05:00
parent ad5b86b5ef
commit 6d6385c6cc
3 changed files with 11 additions and 3 deletions

View File

@ -153,7 +153,7 @@ NS_IMETHODIMP mozPersonalDictionary::Save()
if(NS_FAILED(res)) return res;
nsCOMPtr<nsIOutputStream> outStream;
NS_NewLocalFileOutputStream(getter_AddRefs(outStream), theFile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE ,0664);
NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStream), theFile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE ,0664);
// get a buffered output stream 4096 bytes big, to optimize writes
nsCOMPtr<nsIOutputStream> bufferedOutputStream;
@ -171,6 +171,14 @@ NS_IMETHODIMP mozPersonalDictionary::Save()
bufferedOutputStream->Write(utf8Key.get(), utf8Key.Length(), &bytesWritten);
bufferedOutputStream->Write("\n", 1, &bytesWritten);
}
nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(bufferedOutputStream);
NS_ASSERTION(safeStream, "expected a safe output stream!");
if (safeStream) {
res = safeStream->Finish();
if (NS_FAILED(res)) {
NS_WARNING("failed to save personal dictionary file! possible data loss");
}
}
return res;
}

View File

@ -939,7 +939,7 @@ Preferences::WritePrefFile(nsIFile* aFile)
if (safeStream) {
rv = safeStream->Finish();
if (NS_FAILED(rv)) {
NS_WARNING("failed to save prefs file! possible dataloss");
NS_WARNING("failed to save prefs file! possible data loss");
return rv;
}
}

View File

@ -629,7 +629,7 @@ nsBufferedOutputStream::Flush()
nsresult rv;
uint32_t amt;
if (!mStream) {
// Stream already cancelled/flushed; probably because of error.
// Stream already cancelled/flushed; probably because of previous error.
return NS_OK;
}
rv = Sink()->Write(mBuffer, mFillPoint, &amt);