Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Bug 434805: work harder to recover from url-classifier db corruption.…
Browse files Browse the repository at this point in the history
… r=tony
  • Loading branch information
Dave Camp committed Jun 26, 2008
1 parent ad00948 commit 9f9050e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions toolkit/components/url-classifier/src/Makefile.in
Expand Up @@ -31,6 +31,7 @@ CPPSRCS = \

LOCAL_INCLUDES = \
-I$(srcdir)/../../build \
$(SQLITE_CFLAGS) \
$(NULL)


Expand Down
24 changes: 16 additions & 8 deletions toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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++) {
Expand All @@ -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();
}

Expand Down

0 comments on commit 9f9050e

Please sign in to comment.