Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… r=tony
  • Loading branch information...
commit ac34f6f3bbdc7d7f88e81f3849782adb0b74bb89 1 parent a40af49
Dave Camp authored June 25, 2008
1  toolkit/components/url-classifier/src/Makefile.in
@@ -31,6 +31,7 @@ CPPSRCS = \
31 31
 
32 32
 LOCAL_INCLUDES = \
33 33
                  -I$(srcdir)/../../build \
  34
+                 $(SQLITE_CFLAGS) \
34 35
                  $(NULL)
35 36
 
36 37
 
24  toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -77,6 +77,9 @@
77 77
 #include "prnetdb.h"
78 78
 #include "zlib.h"
79 79
 
  80
+// Needed to interpert mozIStorageConnection::GetLastError
  81
+#include <sqlite3.h>
  82
+
80 83
 /**
81 84
  * The DBServices stores a set of Fragments.  A fragment is one URL
82 85
  * fragment containing two or more domain components and some number
@@ -3056,6 +3059,11 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
3056 3059
   NS_ENSURE_STATE(!mInStream);
3057 3060
   NS_ENSURE_STATE(mUpdateObserver);
3058 3061
 
  3062
+  // We need to get the error code before ApplyUpdate, because it might
  3063
+  // close/open the connection.
  3064
+  PRInt32 errcode = SQLITE_OK;
  3065
+  mConnection->GetLastError(&errcode);
  3066
+
3059 3067
   ApplyUpdate();
3060 3068
 
3061 3069
   if (NS_SUCCEEDED(mUpdateStatus)) {
@@ -3064,7 +3072,13 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
3064 3072
     mUpdateObserver->UpdateError(mUpdateStatus);
3065 3073
   }
3066 3074
 
3067  
-  if (!mResetRequested) {
  3075
+  // It's important that we only reset the database on an update
  3076
+  // command if the update was successful, otherwise unauthenticated
  3077
+  // updates could cause a database reset.
  3078
+  PRBool resetDB = (NS_SUCCEEDED(mUpdateStatus) && mResetRequested) ||
  3079
+                    errcode == SQLITE_CORRUPT;
  3080
+
  3081
+  if (!resetDB) {
3068 3082
     if (NS_SUCCEEDED(mUpdateStatus)) {
3069 3083
       PRInt64 now = (PR_Now() / PR_USEC_PER_SEC);
3070 3084
       for (PRUint32 i = 0; i < mUpdateTables.Length(); i++) {
@@ -3079,15 +3093,9 @@ nsUrlClassifierDBServiceWorker::FinishUpdate()
3079 3093
     }
3080 3094
   }
3081 3095
 
3082  
-  // ResetUpdate() clears mResetRequested...
3083  
-  PRBool resetRequested = mResetRequested;
3084  
-
3085 3096
   ResetUpdate();
3086 3097
 
3087  
-  // It's important that we only reset the database if the update was
3088  
-  // successful, otherwise unauthenticated updates could cause a
3089  
-  // database reset.
3090  
-  if (NS_SUCCEEDED(mUpdateStatus) && resetRequested) {
  3098
+  if (resetDB) {
3091 3099
     ResetDatabase();
3092 3100
   }
3093 3101
 

0 notes on commit ac34f6f

Please sign in to comment.
Something went wrong with that request. Please try again.