| 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_diff_generator.h" | 5 #include "update_engine/delta_diff_generator.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <inttypes.h> | 9 #include <inttypes.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 << kInstallOperationTypes[op->type()]; | 439 << kInstallOperationTypes[op->type()]; |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 struct DeltaObject { | 443 struct DeltaObject { |
| 444 DeltaObject(const string& in_name, const int in_type, const off_t in_size) | 444 DeltaObject(const string& in_name, const int in_type, const off_t in_size) |
| 445 : name(in_name), | 445 : name(in_name), |
| 446 type(in_type), | 446 type(in_type), |
| 447 size(in_size) {} | 447 size(in_size) {} |
| 448 bool operator <(const DeltaObject& object) const { | 448 bool operator <(const DeltaObject& object) const { |
| 449 return size < object.size; | 449 return (size != object.size) ? (size < object.size) : (name < object.name); |
| 450 } | 450 } |
| 451 string name; | 451 string name; |
| 452 int type; | 452 int type; |
| 453 off_t size; | 453 off_t size; |
| 454 }; | 454 }; |
| 455 | 455 |
| 456 void ReportPayloadUsage(const Graph& graph, | 456 void ReportPayloadUsage(const Graph& graph, |
| 457 const DeltaArchiveManifest& manifest, | 457 const DeltaArchiveManifest& manifest, |
| 458 const int64_t manifest_metadata_size) { | 458 const int64_t manifest_metadata_size) { |
| 459 vector<DeltaObject> objects; | 459 vector<DeltaObject> objects; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 &block_size)); | 611 &block_size)); |
| 612 size = static_cast<int64_t>(block_count) * block_size; | 612 size = static_cast<int64_t>(block_count) * block_size; |
| 613 } | 613 } |
| 614 TEST_AND_RETURN_FALSE(size > 0); | 614 TEST_AND_RETURN_FALSE(size > 0); |
| 615 info->set_size(size); | 615 info->set_size(size); |
| 616 OmahaHashCalculator hasher; | 616 OmahaHashCalculator hasher; |
| 617 TEST_AND_RETURN_FALSE(hasher.UpdateFile(partition, size) == size); | 617 TEST_AND_RETURN_FALSE(hasher.UpdateFile(partition, size) == size); |
| 618 TEST_AND_RETURN_FALSE(hasher.Finalize()); | 618 TEST_AND_RETURN_FALSE(hasher.Finalize()); |
| 619 const vector<char>& hash = hasher.raw_hash(); | 619 const vector<char>& hash = hasher.raw_hash(); |
| 620 info->set_hash(hash.data(), hash.size()); | 620 info->set_hash(hash.data(), hash.size()); |
| 621 LOG(INFO) << "hash: " << hasher.hash(); | 621 LOG(INFO) << partition << ": size=" << size << " hash=" << hasher.hash(); |
| 622 return true; | 622 return true; |
| 623 } | 623 } |
| 624 | 624 |
| 625 bool InitializePartitionInfos(const string& old_kernel, | 625 bool InitializePartitionInfos(const string& old_kernel, |
| 626 const string& new_kernel, | 626 const string& new_kernel, |
| 627 const string& old_rootfs, | 627 const string& old_rootfs, |
| 628 const string& new_rootfs, | 628 const string& new_rootfs, |
| 629 DeltaArchiveManifest* manifest) { | 629 DeltaArchiveManifest* manifest) { |
| 630 // TODO(petkov): Generate the old kernel info when we stop generating full | 630 if (!old_kernel.empty()) { |
| 631 // updates for the kernel partition. | 631 TEST_AND_RETURN_FALSE( |
| 632 InitializePartitionInfo(true, |
| 633 old_kernel, |
| 634 manifest->mutable_old_kernel_info())); |
| 635 } |
| 632 TEST_AND_RETURN_FALSE( | 636 TEST_AND_RETURN_FALSE( |
| 633 InitializePartitionInfo(true, | 637 InitializePartitionInfo(true, |
| 634 new_kernel, | 638 new_kernel, |
| 635 manifest->mutable_new_kernel_info())); | 639 manifest->mutable_new_kernel_info())); |
| 636 if (!old_rootfs.empty()) { | 640 if (!old_rootfs.empty()) { |
| 637 TEST_AND_RETURN_FALSE( | 641 TEST_AND_RETURN_FALSE( |
| 638 InitializePartitionInfo(false, | 642 InitializePartitionInfo(false, |
| 639 old_rootfs, | 643 old_rootfs, |
| 640 manifest->mutable_old_rootfs_info())); | 644 manifest->mutable_old_rootfs_info())); |
| 641 } | 645 } |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 | 1518 |
| 1515 LOG(INFO) << "All done. Successfully created delta file."; | 1519 LOG(INFO) << "All done. Successfully created delta file."; |
| 1516 return true; | 1520 return true; |
| 1517 } | 1521 } |
| 1518 | 1522 |
| 1519 const char* const kBsdiffPath = "/usr/bin/bsdiff"; | 1523 const char* const kBsdiffPath = "/usr/bin/bsdiff"; |
| 1520 const char* const kBspatchPath = "/usr/bin/bspatch"; | 1524 const char* const kBspatchPath = "/usr/bin/bspatch"; |
| 1521 const char* const kDeltaMagic = "CrAU"; | 1525 const char* const kDeltaMagic = "CrAU"; |
| 1522 | 1526 |
| 1523 }; // namespace chromeos_update_engine | 1527 }; // namespace chromeos_update_engine |
| OLD | NEW |