Bug 434805: work harder to recover from url-classifier db corruption. r=tony

This commit is contained in:
Dave Camp 2008-06-25 20:23:57 -07:00
parent 9a7bd7aff0
commit 735c08486e
2 changed files with 17 additions and 8 deletions

View File

@ -31,6 +31,7 @@ CPPSRCS = \
LOCAL_INCLUDES = \
-I$(srcdir)/../../build \
$(SQLITE_CFLAGS) \
$(NULL)

View File

@ -77,6 +77,9 @@
#include "prnetdb.h"
#include "zlib.h"
// Needed to interpert mozIStorageConnection::GetLastError
#include <sqlite3.h>
/**
* The DBServices stores a set of Fragments. A fragment is one URL
* fragment containing two or more domain components and some number
@ -3056,6 +3059,11 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
NS_ENSURE_STATE(!mInStream);
NS_ENSURE_STATE(mUpdateObserver);
// We need to get the error code before ApplyUpdate, because it might
// close/open the connection.
PRInt32 errcode = SQLITE_OK;
mConnection->GetLastError(&errcode);
ApplyUpdate();
if (NS_SUCCEEDED(mUpdateStatus)) {
@ -3064,7 +3072,13 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
mUpdateObserver->UpdateError(mUpdateStatus);
}
if (!mResetRequested) {
// It's important that we only reset the database on an update
// command if the update was successful, otherwise unauthenticated
// updates could cause a database reset.
PRBool resetDB = (NS_SUCCEEDED(mUpdateStatus) && mResetRequested) ||
errcode == SQLITE_CORRUPT;
if (!resetDB) {
if (NS_SUCCEEDED(mUpdateStatus)) {
PRInt64 now = (PR_Now() / PR_USEC_PER_SEC);
for (PRUint32 i = 0; i < mUpdateTables.Length(); i++) {
@ -3079,15 +3093,9 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
}
}
// ResetUpdate() clears mResetRequested...
PRBool resetRequested = mResetRequested;
ResetUpdate();
// It's important that we only reset the database if the update was
// successful, otherwise unauthenticated updates could cause a
// database reset.
if (NS_SUCCEEDED(mUpdateStatus) && resetRequested) {
if (resetDB) {
ResetDatabase();
}