From 3edbcc07420fa3093e9f96503ddee34cd6c05aec Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Mon, 29 May 2006 16:59:35 +0000 Subject: [PATCH] Make nsAutoCompleteMdbResult::RemoveValueAt do a CompressCommit after removing the mork row, to avoid corruption at shutdown. Also CutAllColumns like the corresponding history method does. Bug 242207, r=brettw sr/a=mconnor git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@198574 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/nsAutoCompleteMdbResult.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp b/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp index 072bd57186d..ffb269476e8 100644 --- a/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp +++ b/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp @@ -227,8 +227,33 @@ nsAutoCompleteMdbResult::RemoveValueAt(PRInt32 aRowIndex, PRBool aRemoveFromDb) NS_ENSURE_TRUE(row, NS_ERROR_INVALID_ARG); if (aRemoveFromDb && mTable && mEnv) { + // TODO: share this code with nsGlobalHistory::RemovePageInternal(), + // rather than duplicating it here. + + nsIMdbPort *port = nsnull; + mTable->GetPort(mEnv, &port); // note: doesn't addref + + nsCOMPtr store = do_QueryInterface(port); + NS_ENSURE_TRUE(store, NS_ERROR_FAILURE); + mdb_err err = mTable->CutRow(mEnv, row); NS_ENSURE_TRUE(!err, NS_ERROR_FAILURE); + + row->CutAllColumns(mEnv); + + // We must do a CompressCommit on the store now. If we don't, + // mork can leave the file in an inconsistent state, which causes it to + // be killed the next time it's opened. + + nsCOMPtr thumb; + err = store->CompressCommit(mEnv, getter_AddRefs(thumb)); + if (err == 0) { + mdb_count total, current; + mdb_bool done, broken; + do { + err = thumb->DoMore(mEnv, &total, ¤t, &done, &broken); + } while ((err == 0) && !broken && !done); + } } mResults.RemoveObjectAt(aRowIndex);