• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 //
16 
17 #include "update_engine/payload_consumer/install_plan.h"
18 
19 #include <base/format_macros.h>
20 #include <base/logging.h>
21 #include <base/strings/string_number_conversions.h>
22 #include <base/strings/stringprintf.h>
23 
24 #include "update_engine/common/utils.h"
25 #include "update_engine/payload_consumer/payload_constants.h"
26 
27 using std::string;
28 
29 namespace chromeos_update_engine {
30 
InstallPayloadTypeToString(InstallPayloadType type)31 string InstallPayloadTypeToString(InstallPayloadType type) {
32   switch (type) {
33     case InstallPayloadType::kUnknown:
34       return "unknown";
35     case InstallPayloadType::kFull:
36       return "full";
37     case InstallPayloadType::kDelta:
38       return "delta";
39   }
40   return "invalid type";
41 }
42 
operator ==(const InstallPlan & that) const43 bool InstallPlan::operator==(const InstallPlan& that) const {
44   return ((is_resume == that.is_resume) &&
45           (download_url == that.download_url) && (payloads == that.payloads) &&
46           (source_slot == that.source_slot) &&
47           (target_slot == that.target_slot) && (partitions == that.partitions));
48 }
49 
operator !=(const InstallPlan & that) const50 bool InstallPlan::operator!=(const InstallPlan& that) const {
51   return !((*this) == that);
52 }
53 
Dump() const54 void InstallPlan::Dump() const {
55   string partitions_str;
56   for (const auto& partition : partitions) {
57     partitions_str +=
58         base::StringPrintf(", part: %s (source_size: %" PRIu64
59                            ", target_size %" PRIu64 ", postinst:%s)",
60                            partition.name.c_str(),
61                            partition.source_size,
62                            partition.target_size,
63                            utils::ToString(partition.run_postinstall).c_str());
64   }
65   string payloads_str;
66   for (const auto& payload : payloads) {
67     payloads_str += base::StringPrintf(
68         ", payload: (size: %" PRIu64 ", metadata_size: %" PRIu64
69         ", metadata signature: %s, hash: %s, payload type: %s)",
70         payload.size,
71         payload.metadata_size,
72         payload.metadata_signature.c_str(),
73         base::HexEncode(payload.hash.data(), payload.hash.size()).c_str(),
74         InstallPayloadTypeToString(payload.type).c_str());
75   }
76 
77   string version_str = base::StringPrintf(", version: %s", version.c_str());
78   if (!system_version.empty()) {
79     version_str +=
80         base::StringPrintf(", system_version: %s", system_version.c_str());
81   }
82 
83   LOG(INFO) << "InstallPlan: " << (is_resume ? "resume" : "new_update")
84             << version_str
85             << ", source_slot: " << BootControlInterface::SlotName(source_slot)
86             << ", target_slot: " << BootControlInterface::SlotName(target_slot)
87             << ", url: " << download_url << payloads_str << partitions_str
88             << ", hash_checks_mandatory: "
89             << utils::ToString(hash_checks_mandatory)
90             << ", powerwash_required: " << utils::ToString(powerwash_required)
91             << ", switch_slot_on_reboot: "
92             << utils::ToString(switch_slot_on_reboot)
93             << ", run_post_install: " << utils::ToString(run_post_install);
94 }
95 
LoadPartitionsFromSlots(BootControlInterface * boot_control)96 bool InstallPlan::LoadPartitionsFromSlots(BootControlInterface* boot_control) {
97   bool result = true;
98   for (Partition& partition : partitions) {
99     if (source_slot != BootControlInterface::kInvalidSlot) {
100       result = boot_control->GetPartitionDevice(
101           partition.name, source_slot, &partition.source_path) && result;
102     } else {
103       partition.source_path.clear();
104     }
105 
106     if (target_slot != BootControlInterface::kInvalidSlot) {
107       result = boot_control->GetPartitionDevice(
108           partition.name, target_slot, &partition.target_path) && result;
109     } else {
110       partition.target_path.clear();
111     }
112   }
113   return result;
114 }
115 
operator ==(const InstallPlan::Partition & that) const116 bool InstallPlan::Partition::operator==(
117     const InstallPlan::Partition& that) const {
118   return (name == that.name &&
119           source_path == that.source_path &&
120           source_size == that.source_size &&
121           source_hash == that.source_hash &&
122           target_path == that.target_path &&
123           target_size == that.target_size &&
124           target_hash == that.target_hash &&
125           run_postinstall == that.run_postinstall &&
126           postinstall_path == that.postinstall_path &&
127           filesystem_type == that.filesystem_type &&
128           postinstall_optional == that.postinstall_optional);
129 }
130 
131 }  // namespace chromeos_update_engine
132