blob: fa6dff7e6ad5fea72d0a7ac0023511b413efd52a [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2013 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Jay Srinivasanae4697c2013-03-18 17:08:08 -070016
17#include "update_engine/install_plan.h"
18
Alex Deymoe5e5fe92015-10-05 09:28:19 -070019#include <base/format_macros.h>
Alex Deymo8427b4a2014-11-05 14:00:32 -080020#include <base/logging.h>
Alex Deymoe5e5fe92015-10-05 09:28:19 -070021#include <base/strings/stringprintf.h>
Jay Srinivasanae4697c2013-03-18 17:08:08 -070022
Sen Jiang70a6ab02015-08-28 13:23:27 -070023#include "update_engine/payload_constants.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070024#include "update_engine/utils.h"
25
26using std::string;
27
28namespace chromeos_update_engine {
29
30InstallPlan::InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070031 bool is_full_update,
Jay Srinivasanae4697c2013-03-18 17:08:08 -070032 const string& url,
33 uint64_t payload_size,
34 const string& payload_hash,
35 uint64_t metadata_size,
36 const string& metadata_signature,
Alex Deymof329b932014-10-30 01:37:48 -070037 const string& public_key_rsa)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070038 : is_resume(is_resume),
Gilad Arnold21504f02013-05-24 08:51:22 -070039 is_full_update(is_full_update),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070040 download_url(url),
41 payload_size(payload_size),
42 payload_hash(payload_hash),
43 metadata_size(metadata_size),
44 metadata_signature(metadata_signature),
Jay Srinivasanae4697c2013-03-18 17:08:08 -070045 hash_checks_mandatory(false),
David Zeuthene7f89172013-10-31 10:21:04 -070046 powerwash_required(false),
47 public_key_rsa(public_key_rsa) {}
Jay Srinivasanae4697c2013-03-18 17:08:08 -070048
Jay Srinivasanae4697c2013-03-18 17:08:08 -070049
50bool InstallPlan::operator==(const InstallPlan& that) const {
51 return ((is_resume == that.is_resume) &&
Gilad Arnold21504f02013-05-24 08:51:22 -070052 (is_full_update == that.is_full_update) &&
Jay Srinivasanae4697c2013-03-18 17:08:08 -070053 (download_url == that.download_url) &&
54 (payload_size == that.payload_size) &&
55 (payload_hash == that.payload_hash) &&
56 (metadata_size == that.metadata_size) &&
57 (metadata_signature == that.metadata_signature) &&
Alex Deymo763e7db2015-08-27 21:08:08 -070058 (source_slot == that.source_slot) &&
59 (target_slot == that.target_slot) &&
Alex Deymoe5e5fe92015-10-05 09:28:19 -070060 (partitions == that.partitions));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070061}
62
63bool InstallPlan::operator!=(const InstallPlan& that) const {
64 return !((*this) == that);
65}
66
67void InstallPlan::Dump() const {
Alex Deymoe5e5fe92015-10-05 09:28:19 -070068 string partitions_str;
69 for (const auto& partition : partitions) {
70 partitions_str += base::StringPrintf(
71 ", part: %s (source_size: %" PRIu64 ", target_size %" PRIu64 ")",
72 partition.name.c_str(), partition.source_size, partition.target_size);
73 }
74
Jay Srinivasanae4697c2013-03-18 17:08:08 -070075 LOG(INFO) << "InstallPlan: "
Gilad Arnold21504f02013-05-24 08:51:22 -070076 << (is_resume ? "resume" : "new_update")
77 << ", payload type: " << (is_full_update ? "full" : "delta")
Alex Deymo763e7db2015-08-27 21:08:08 -070078 << ", source_slot: " << BootControlInterface::SlotName(source_slot)
79 << ", target_slot: " << BootControlInterface::SlotName(target_slot)
Jay Srinivasanae4697c2013-03-18 17:08:08 -070080 << ", url: " << download_url
81 << ", payload size: " << payload_size
82 << ", payload hash: " << payload_hash
83 << ", metadata size: " << metadata_size
84 << ", metadata signature: " << metadata_signature
Alex Deymoe5e5fe92015-10-05 09:28:19 -070085 << partitions_str
Jay Srinivasanae4697c2013-03-18 17:08:08 -070086 << ", hash_checks_mandatory: " << utils::ToString(
87 hash_checks_mandatory)
88 << ", powerwash_required: " << utils::ToString(
89 powerwash_required);
90}
91
Alex Deymo763e7db2015-08-27 21:08:08 -070092bool InstallPlan::LoadPartitionsFromSlots(SystemState* system_state) {
93 bool result = true;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070094 for (Partition& partition : partitions) {
95 if (source_slot != BootControlInterface::kInvalidSlot) {
96 result = system_state->boot_control()->GetPartitionDevice(
97 partition.name, source_slot, &partition.source_path) && result;
98 } else {
99 partition.source_path.clear();
100 }
Alex Deymo763e7db2015-08-27 21:08:08 -0700101
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700102 if (target_slot != BootControlInterface::kInvalidSlot) {
103 result = system_state->boot_control()->GetPartitionDevice(
104 partition.name, target_slot, &partition.target_path) && result;
105 } else {
106 partition.target_path.clear();
107 }
Alex Deymo763e7db2015-08-27 21:08:08 -0700108 }
109 return result;
110}
111
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700112bool InstallPlan::Partition::operator==(
113 const InstallPlan::Partition& that) const {
114 return (name == that.name &&
115 source_path == that.source_path &&
116 source_size == that.source_size &&
117 source_hash == that.source_hash &&
118 target_path == that.target_path &&
119 target_size == that.target_size &&
120 target_hash == that.target_hash &&
121 run_postinstall == that.run_postinstall);
122}
123
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700124} // namespace chromeos_update_engine