OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/delta_performer.h" | 5 #include "update_engine/delta_performer.h" |
6 | 6 |
7 #include <endian.h> | 7 #include <endian.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 (next_operation_num_ + 1 == total_operations)) { | 215 (next_operation_num_ + 1 == total_operations)) { |
216 LOG(INFO) << "Performing operation " << (next_operation_num_ + 1) << "/" | 216 LOG(INFO) << "Performing operation " << (next_operation_num_ + 1) << "/" |
217 << total_operations; | 217 << total_operations; |
218 } | 218 } |
219 bool is_kernel_partition = | 219 bool is_kernel_partition = |
220 (next_operation_num_ >= manifest_.install_operations_size()); | 220 (next_operation_num_ >= manifest_.install_operations_size()); |
221 // If about to start a non-idempotent operation, clear the update state so | 221 // If about to start a non-idempotent operation, clear the update state so |
222 // that if the operation gets interrupted, we don't try to resume the | 222 // that if the operation gets interrupted, we don't try to resume the |
223 // update. | 223 // update. |
224 if (!IsIdempotentOperation(op)) { | 224 if (!IsIdempotentOperation(op)) { |
225 ResetUpdateProgress(); | 225 ResetUpdateProgress(prefs_); |
226 } | 226 } |
227 if (op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE || | 227 if (op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE || |
228 op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) { | 228 op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) { |
229 if (!PerformReplaceOperation(op, is_kernel_partition)) { | 229 if (!PerformReplaceOperation(op, is_kernel_partition)) { |
230 LOG(ERROR) << "Failed to perform replace operation " | 230 LOG(ERROR) << "Failed to perform replace operation " |
231 << next_operation_num_; | 231 << next_operation_num_; |
232 return -EINVAL; | 232 return -EINVAL; |
233 } | 233 } |
234 } else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE) { | 234 } else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE) { |
235 if (!PerformMoveOperation(op, is_kernel_partition)) { | 235 if (!PerformMoveOperation(op, is_kernel_partition)) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 return hash_data == signed_hash_data; | 505 return hash_data == signed_hash_data; |
506 } | 506 } |
507 | 507 |
508 void DeltaPerformer::DiscardBufferHeadBytes(size_t count, bool do_hash) { | 508 void DeltaPerformer::DiscardBufferHeadBytes(size_t count, bool do_hash) { |
509 if (do_hash) { | 509 if (do_hash) { |
510 hash_calculator_.Update(&buffer_[0], count); | 510 hash_calculator_.Update(&buffer_[0], count); |
511 } | 511 } |
512 buffer_.erase(buffer_.begin(), buffer_.begin() + count); | 512 buffer_.erase(buffer_.begin(), buffer_.begin() + count); |
513 } | 513 } |
514 | 514 |
515 bool DeltaPerformer::ResetUpdateProgress() { | 515 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, |
516 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextOperation, | 516 string update_check_response_hash) { |
517 kUpdateStateOperationInvalid)); | 517 int64_t next_operation = kUpdateStateOperationInvalid; |
| 518 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextOperation, |
| 519 &next_operation) && |
| 520 next_operation != kUpdateStateOperationInvalid && |
| 521 next_operation > 0); |
| 522 |
| 523 string interrupted_hash; |
| 524 TEST_AND_RETURN_FALSE(prefs->GetString(kPrefsUpdateCheckResponseHash, |
| 525 &interrupted_hash) && |
| 526 !interrupted_hash.empty() && |
| 527 interrupted_hash == update_check_response_hash); |
| 528 |
| 529 // Sanity check the rest. |
| 530 int64_t next_data_offset = -1; |
| 531 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextDataOffset, |
| 532 &next_data_offset) && |
| 533 next_data_offset >= 0); |
| 534 |
| 535 string signed_sha256_context; |
| 536 TEST_AND_RETURN_FALSE( |
| 537 prefs->GetString(kPrefsUpdateStateSignedSHA256Context, |
| 538 &signed_sha256_context) && |
| 539 !signed_sha256_context.empty()); |
| 540 |
| 541 int64_t manifest_metadata_size = 0; |
| 542 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsManifestMetadataSize, |
| 543 &manifest_metadata_size) && |
| 544 manifest_metadata_size > 0); |
| 545 |
| 546 return true; |
| 547 } |
| 548 |
| 549 bool DeltaPerformer::ResetUpdateProgress(PrefsInterface* prefs) { |
| 550 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation, |
| 551 kUpdateStateOperationInvalid)); |
518 return true; | 552 return true; |
519 } | 553 } |
520 | 554 |
521 bool DeltaPerformer::CheckpointUpdateProgress() { | 555 bool DeltaPerformer::CheckpointUpdateProgress() { |
522 // First reset the progress in case we die in the middle of the state update. | 556 // First reset the progress in case we die in the middle of the state update. |
523 ResetUpdateProgress(); | 557 ResetUpdateProgress(prefs_); |
524 TEST_AND_RETURN_FALSE(prefs_->SetString(kPrefsUpdateStateSignedSHA256Context, | 558 if (last_updated_buffer_offset_ != buffer_offset_) { |
525 hash_calculator_.GetContext())); | 559 TEST_AND_RETURN_FALSE( |
526 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, | 560 prefs_->SetString(kPrefsUpdateStateSignedSHA256Context, |
527 buffer_offset_)); | 561 hash_calculator_.GetContext())); |
| 562 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, |
| 563 buffer_offset_)); |
| 564 last_updated_buffer_offset_ = buffer_offset_; |
| 565 } |
528 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextOperation, | 566 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextOperation, |
529 next_operation_num_)); | 567 next_operation_num_)); |
530 return true; | 568 return true; |
531 } | 569 } |
532 | 570 |
533 } // namespace chromeos_update_engine | 571 } // namespace chromeos_update_engine |
OLD | NEW |