| 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/download_action.h" | 5 #include "update_engine/download_action.h" |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <glib.h> | 10 #include <glib.h> |
| 11 #include "update_engine/action_pipe.h" | 11 #include "update_engine/action_pipe.h" |
| 12 #include "update_engine/subprocess.h" | 12 #include "update_engine/subprocess.h" |
| 13 | 13 |
| 14 using std::min; | 14 using std::min; |
| 15 using std::string; | 15 using std::string; |
| 16 using std::vector; | 16 using std::vector; |
| 17 | 17 |
| 18 namespace chromeos_update_engine { | 18 namespace chromeos_update_engine { |
| 19 | 19 |
| 20 // Use a buffer to reduce the number of IOPS on SSD devices. | 20 // Use a buffer to reduce the number of IOPS on SSD devices. |
| 21 const size_t kFileWriterBufferSize = 128 * 1024; // 128 KiB | 21 const size_t kFileWriterBufferSize = 128 * 1024; // 128 KiB |
| 22 | 22 |
| 23 DownloadAction::DownloadAction(PrefsInterface* prefs, | 23 DownloadAction::DownloadAction(PrefsInterface* prefs, |
| 24 HttpFetcher* http_fetcher) | 24 HttpFetcher* http_fetcher) |
| 25 : prefs_(prefs), | 25 : prefs_(prefs), |
| 26 writer_(NULL), | 26 writer_(NULL), |
| 27 http_fetcher_(http_fetcher), | 27 http_fetcher_(http_fetcher), |
| 28 code_(kActionCodeSuccess), | 28 code_(kActionCodeSuccess), |
| 29 delegate_(NULL), | 29 delegate_(NULL), |
| 30 bytes_received_(0) {} | 30 bytes_received_(0), |
| 31 skip_reporting_signature_fail_(NULL) {} |
| 31 | 32 |
| 32 DownloadAction::~DownloadAction() {} | 33 DownloadAction::~DownloadAction() {} |
| 33 | 34 |
| 34 void DownloadAction::PerformAction() { | 35 void DownloadAction::PerformAction() { |
| 35 http_fetcher_->set_delegate(this); | 36 http_fetcher_->set_delegate(this); |
| 36 | 37 |
| 37 // Get the InstallPlan and read it | 38 // Get the InstallPlan and read it |
| 38 CHECK(HasInputObject()); | 39 CHECK(HasInputObject()); |
| 39 install_plan_ = GetInputObject(); | 40 install_plan_ = GetInputObject(); |
| 40 bytes_received_ = 0; | 41 bytes_received_ = 0; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 151 } |
| 151 | 152 |
| 152 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { | 153 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { |
| 153 if (writer_) { | 154 if (writer_) { |
| 154 LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer."; | 155 LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer."; |
| 155 writer_ = NULL; | 156 writer_ = NULL; |
| 156 } | 157 } |
| 157 if (delegate_) { | 158 if (delegate_) { |
| 158 delegate_->SetDownloadStatus(false); // Set to inactive. | 159 delegate_->SetDownloadStatus(false); // Set to inactive. |
| 159 } | 160 } |
| 161 bool signature_verify_failed = false; |
| 160 ActionExitCode code = | 162 ActionExitCode code = |
| 161 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError; | 163 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError; |
| 162 if (code == kActionCodeSuccess) { | 164 if (code == kActionCodeSuccess) { |
| 163 if (!install_plan_.is_full_update) { | 165 if (!install_plan_.is_full_update) { |
| 164 if (!delta_performer_->VerifyPayload("", | 166 if (!delta_performer_->VerifyPayload("", |
| 165 install_plan_.download_hash, | 167 install_plan_.download_hash, |
| 166 install_plan_.size, | 168 install_plan_.size, |
| 167 NULL)) { | 169 &signature_verify_failed)) { |
| 168 LOG(ERROR) << "Download of " << install_plan_.download_url | 170 LOG(ERROR) << "Download of " << install_plan_.download_url |
| 169 << " failed due to payload verification error."; | 171 << " failed due to payload verification error."; |
| 170 code = kActionCodeDownloadPayloadVerificationError; | 172 code = kActionCodeDownloadPayloadVerificationError; |
| 171 } else if (!delta_performer_->GetNewPartitionInfo( | 173 } else if (!delta_performer_->GetNewPartitionInfo( |
| 172 &install_plan_.kernel_size, | 174 &install_plan_.kernel_size, |
| 173 &install_plan_.kernel_hash, | 175 &install_plan_.kernel_hash, |
| 174 &install_plan_.rootfs_size, | 176 &install_plan_.rootfs_size, |
| 175 &install_plan_.rootfs_hash)) { | 177 &install_plan_.rootfs_hash)) { |
| 176 LOG(ERROR) << "Unable to get new partition hash info."; | 178 LOG(ERROR) << "Unable to get new partition hash info."; |
| 177 code = kActionCodeDownloadNewPartitionInfoError; | 179 code = kActionCodeDownloadNewPartitionInfoError; |
| 178 } | 180 } |
| 179 } else { | 181 } else { |
| 180 // Makes sure the hash and size are correct for an old-style full update. | 182 // Makes sure the hash and size are correct for an old-style full update. |
| 181 omaha_hash_calculator_.Finalize(); | 183 omaha_hash_calculator_.Finalize(); |
| 182 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { | 184 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { |
| 183 LOG(ERROR) << "Download of " << install_plan_.download_url | 185 LOG(ERROR) << "Download of " << install_plan_.download_url |
| 184 << " failed. Expected hash " << install_plan_.download_hash | 186 << " failed. Expected hash " << install_plan_.download_hash |
| 185 << " but got hash " << omaha_hash_calculator_.hash(); | 187 << " but got hash " << omaha_hash_calculator_.hash(); |
| 186 code = kActionCodeDownloadHashMismatchError; | 188 code = kActionCodeDownloadHashMismatchError; |
| 187 } else if (bytes_received_ != install_plan_.size) { | 189 } else if (bytes_received_ != install_plan_.size) { |
| 188 LOG(ERROR) << "Download of " << install_plan_.download_url | 190 LOG(ERROR) << "Download of " << install_plan_.download_url |
| 189 << " failed. Expected size " << install_plan_.size | 191 << " failed. Expected size " << install_plan_.size |
| 190 << " but got size " << bytes_received_; | 192 << " but got size " << bytes_received_; |
| 191 code = kActionCodeDownloadSizeMismatchError; | 193 code = kActionCodeDownloadSizeMismatchError; |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 | 197 |
| 198 if (skip_reporting_signature_fail_.get() && |
| 199 (code != kActionCodeSuccess || !signature_verify_failed)) { |
| 200 LOG(INFO) << "Suppressing signature pub key verification warning"; |
| 201 skip_reporting_signature_fail_->Run(); |
| 202 } |
| 203 |
| 196 FlushLinuxCaches(); | 204 FlushLinuxCaches(); |
| 197 | 205 |
| 198 // Write the path to the output pipe if we're successful. | 206 // Write the path to the output pipe if we're successful. |
| 199 if (code == kActionCodeSuccess && HasOutputPipe()) | 207 if (code == kActionCodeSuccess && HasOutputPipe()) |
| 200 SetOutputObject(install_plan_); | 208 SetOutputObject(install_plan_); |
| 201 processor_->ActionComplete(this, code); | 209 processor_->ActionComplete(this, code); |
| 202 } | 210 } |
| 203 | 211 |
| 204 void DownloadAction::TransferTerminated(HttpFetcher *fetcher) { | 212 void DownloadAction::TransferTerminated(HttpFetcher *fetcher) { |
| 205 if (code_ != kActionCodeSuccess) { | 213 if (code_ != kActionCodeSuccess) { |
| 206 processor_->ActionComplete(this, code_); | 214 processor_->ActionComplete(this, code_); |
| 207 } | 215 } |
| 208 } | 216 } |
| 209 | 217 |
| 210 }; // namespace {} | 218 }; // namespace {} |
| OLD | NEW |