Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1012)

Unified Diff: chrome/browser/sync/syncable/directory_backing_store.cc

Issue 1733008: Delete and recreate the sync database if it is corrupt. (Closed)
Patch Set: Use scoped_sqlite_db_ptr Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/syncable/directory_backing_store.cc
diff --git a/chrome/browser/sync/syncable/directory_backing_store.cc b/chrome/browser/sync/syncable/directory_backing_store.cc
index 2635defce745fb839b8acd5af7bd4e7cd7e7cd9e..9c86ea76a5b6350fb90192ff8226d396826e72fb 100644
--- a/chrome/browser/sync/syncable/directory_backing_store.cc
+++ b/chrome/browser/sync/syncable/directory_backing_store.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,6 +12,7 @@
#include <limits>
+#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
@@ -179,19 +180,22 @@ DirectoryBackingStore::~DirectoryBackingStore() {
bool DirectoryBackingStore::OpenAndConfigureHandleHelper(
sqlite3** handle) const {
if (SQLITE_OK == OpenSqliteDb(backing_filepath_, handle)) {
+ sqlite_utils::scoped_sqlite_db_ptr scoped_handle(*handle);
sqlite3_busy_timeout(*handle, std::numeric_limits<int>::max());
{
SQLStatement statement;
statement.prepare(*handle, "PRAGMA fullfsync = 1");
if (SQLITE_DONE != statement.step()) {
- LOG(FATAL) << sqlite3_errmsg(*handle);
+ LOG(ERROR) << sqlite3_errmsg(*handle);
+ return false;
}
}
{
SQLStatement statement;
statement.prepare(*handle, "PRAGMA synchronous = 2");
if (SQLITE_DONE != statement.step()) {
- LOG(FATAL) << sqlite3_errmsg(*handle);
+ LOG(ERROR) << sqlite3_errmsg(*handle);
+ return false;
}
}
sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs);
@@ -204,6 +208,7 @@ bool DirectoryBackingStore::OpenAndConfigureHandleHelper(
attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
#endif
+ scoped_handle.release();
tim (not reviewing) 2010/04/27 14:25:03 this is necessary?
albertb 2010/04/27 15:05:41 Yes. If the scoped ptr holds a valid db handle, it
return true;
}
return false;
@@ -230,6 +235,13 @@ DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket,
bool DirectoryBackingStore::BeginLoad() {
DCHECK(load_dbhandle_ == NULL);
+ bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_);
+ if (ret)
+ return ret;
+ // Something's gone wrong. Nuke the database and try again.
+ LOG(ERROR) << "Sync database " << backing_filepath_.value()
+ << " corrupt. Deleting and recreating.";
+ file_util::Delete(backing_filepath_, false);
return OpenAndConfigureHandleHelper(&load_dbhandle_);
}

Powered by Google App Engine
This is Rietveld 408576698