OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 it->key() != GetHeaderDBKey() || // Header entry must come first. | 443 it->key() != GetHeaderDBKey() || // Header entry must come first. |
444 !header.ParseFromArray(it->value().data(), it->value().size()) || | 444 !header.ParseFromArray(it->value().data(), it->value().size()) || |
445 header.version() != kDBVersion) { | 445 header.version() != kDBVersion) { |
446 DLOG(ERROR) << "Invalid header detected. version = " << header.version(); | 446 DLOG(ERROR) << "Invalid header detected. version = " << header.version(); |
447 return false; | 447 return false; |
448 } | 448 } |
449 | 449 |
450 // Check all entires. | 450 // Check all entires. |
451 size_t num_checked_child_map_entries = 0; | 451 size_t num_checked_child_map_entries = 0; |
452 DriveEntryProto entry; | 452 DriveEntryProto entry; |
| 453 std::string serialized_parent_entry; |
453 std::string child_resource_id; | 454 std::string child_resource_id; |
454 for (it->Next(); it->Valid(); it->Next()) { | 455 for (it->Next(); it->Valid(); it->Next()) { |
455 // Check if stored data is broken. | 456 // Check if stored data is broken. |
456 if (!entry.ParseFromArray(it->value().data(), it->value().size()) || | 457 if (!entry.ParseFromArray(it->value().data(), it->value().size()) || |
457 entry.resource_id() != it->key()) { | 458 entry.resource_id() != it->key()) { |
458 DLOG(ERROR) << "Broken entry detected"; | 459 DLOG(ERROR) << "Broken entry detected"; |
459 return false; | 460 return false; |
460 } | 461 } |
461 | 462 |
462 // Check if parent-child relationship is stored correctly. | |
463 if (!entry.parent_resource_id().empty()) { | 463 if (!entry.parent_resource_id().empty()) { |
464 leveldb::Status status = child_map_->Get( | 464 // Check if the parent entry is stored. |
| 465 leveldb::Status status = resource_map_->Get( |
| 466 options, |
| 467 leveldb::Slice(entry.parent_resource_id()), |
| 468 &serialized_parent_entry); |
| 469 if (!status.ok()) { |
| 470 DLOG(ERROR) << "Can't get parent entry. status = " << status.ToString(); |
| 471 return false; |
| 472 } |
| 473 |
| 474 // Check if parent-child relationship is stored correctly. |
| 475 status = child_map_->Get( |
465 options, | 476 options, |
466 leveldb::Slice(GetChildMapKey(entry.parent_resource_id(), | 477 leveldb::Slice(GetChildMapKey(entry.parent_resource_id(), |
467 entry.base_name())), | 478 entry.base_name())), |
468 &child_resource_id); | 479 &child_resource_id); |
469 if (!status.ok() || child_resource_id != entry.resource_id()) { | 480 if (!status.ok() || child_resource_id != entry.resource_id()) { |
470 DLOG(ERROR) << "Child map is broken. status = " << status.ToString(); | 481 DLOG(ERROR) << "Child map is broken. status = " << status.ToString(); |
471 return false; | 482 return false; |
472 } | 483 } |
473 ++num_checked_child_map_entries; | 484 ++num_checked_child_map_entries; |
474 } | 485 } |
(...skipping 14 matching lines...) Expand all Loading... |
489 num_child_map_entries != num_checked_child_map_entries) { | 500 num_child_map_entries != num_checked_child_map_entries) { |
490 DLOG(ERROR) << "Error during checking child map. status = " | 501 DLOG(ERROR) << "Error during checking child map. status = " |
491 << it->status().ToString(); | 502 << it->status().ToString(); |
492 return false; | 503 return false; |
493 } | 504 } |
494 | 505 |
495 return true; | 506 return true; |
496 } | 507 } |
497 | 508 |
498 } // namespace drive | 509 } // namespace drive |
OLD | NEW |