Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug 434805: work harder to recover from url-classifier db corruption.…

… r=tony
  • Loading branch information...
commit 9f9050e86669f1e4f059fda8375f4b7627a08a9a 1 parent ad00948
@campd campd authored
View
1  toolkit/components/url-classifier/src/Makefile.in
@@ -31,6 +31,7 @@ CPPSRCS = \
LOCAL_INCLUDES = \
-I$(srcdir)/../../build \
+ $(SQLITE_CFLAGS) \
$(NULL)
View
24 toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -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();
}
Please sign in to comment.
Something went wrong with that request. Please try again.