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

Unified Diff: sync/syncable/directory_backing_store.cc

Issue 10821121: sync: Attempt to recover from directory corruption (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix other win compile warning Created 8 years, 4 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
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/directory_backing_store.cc
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc
index f1bfe8c4190d9a3856bac6be9f20ebe398e75d4e..f7acdf8ce6b50e2dea355386122c66e43901db71 100644
--- a/sync/syncable/directory_backing_store.cc
+++ b/sync/syncable/directory_backing_store.cc
@@ -9,6 +9,7 @@
#include <limits>
#include "base/base64.h"
+#include "base/debug/trace_event.h"
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/logging.h"
@@ -1083,5 +1084,36 @@ bool DirectoryBackingStore::CreateShareInfoTableVersion71(
return db_->Execute(query.c_str());
}
+// This function checks to see if the given list of Metahandles has any nodes
+// whose PREV_ID, PARENT_ID or NEXT_ID values refer to ID values that do not
+// actually exist. Returns true on success.
+bool DirectoryBackingStore::VerifyReferenceIntegrity(
+ const syncable::MetahandlesIndex &index) {
+ TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck");
+ using namespace syncable;
+ typedef base::hash_set<std::string> IdsSet;
+
+ IdsSet ids_set;
+ bool is_ok = true;
+
+ for (MetahandlesIndex::const_iterator it = index.begin();
+ it != index.end(); ++it) {
+ EntryKernel* entry = *it;
+ bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second);
+ is_ok = is_ok && !is_duplicate_id;
+ }
+
+ IdsSet::iterator end = ids_set.end();
+ for (MetahandlesIndex::const_iterator it = index.begin();
+ it != index.end(); ++it) {
+ EntryKernel* entry = *it;
+ bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end);
+ bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end);
+ bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end);
+ is_ok = is_ok && prev_exists && parent_exists && next_exists;
+ }
+ return is_ok;
+}
+
} // namespace syncable
} // namespace syncer
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698