Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/omaha_response_handler_action.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <string> |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 8 | |
| 9 | #include <base/logging.h> |
| 10 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 11 | #include "update_engine/delta_performer.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 12 | #include "update_engine/prefs_interface.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 13 | #include "update_engine/utils.h" |
| 14 | |
| 15 | using std::string; |
| 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 19 | const char OmahaResponseHandlerAction::kDeadlineFile[] = |
| 20 | "/tmp/update-check-response-deadline"; |
| 21 | |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 22 | OmahaResponseHandlerAction::OmahaResponseHandlerAction(PrefsInterface* prefs) |
| 23 | : prefs_(prefs), |
| 24 | got_no_update_response_(false), |
| 25 | key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath) {} |
| 26 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 27 | void OmahaResponseHandlerAction::PerformAction() { |
| 28 | CHECK(HasInputObject()); |
| 29 | ScopedActionCompleter completer(processor_, this); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 30 | const OmahaResponse& response = GetInputObject(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 31 | if (!response.update_exists) { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 32 | got_no_update_response_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 33 | LOG(INFO) << "There are no updates. Aborting."; |
| 34 | return; |
| 35 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 36 | install_plan_.download_url = response.codebase; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 37 | install_plan_.payload_size = response.size; |
| 38 | install_plan_.payload_hash = response.hash; |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 39 | install_plan_.metadata_size = response.metadata_size; |
| 40 | install_plan_.metadata_signature = response.metadata_signature; |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 41 | |
| 42 | install_plan_.is_resume = |
| 43 | DeltaPerformer::CanResumeUpdate(prefs_, response.hash); |
| 44 | if (!install_plan_.is_resume) { |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 45 | LOG_IF(WARNING, !DeltaPerformer::ResetUpdateProgress(prefs_, false)) |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 46 | << "Unable to reset the update progress."; |
| 47 | LOG_IF(WARNING, !prefs_->SetString(kPrefsUpdateCheckResponseHash, |
| 48 | response.hash)) |
| 49 | << "Unable to save the update check response hash."; |
| 50 | } |
| 51 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | TEST_AND_RETURN(GetInstallDev( |
| 53 | (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 54 | &install_plan_.install_path)); |
| 55 | install_plan_.kernel_install_path = |
| 56 | utils::BootKernelDevice(install_plan_.install_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 57 | |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 58 | TEST_AND_RETURN(HasOutputPipe()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 59 | if (HasOutputPipe()) |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 60 | SetOutputObject(install_plan_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 61 | LOG(INFO) << "Using this install plan:"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 62 | install_plan_.Dump(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 63 | |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 64 | // Send the deadline data (if any) to Chrome through a file. This is a pretty |
| 65 | // hacky solution but should be OK for now. |
| 66 | // |
| 67 | // TODO(petkov): Rearchitect this to avoid communication through a |
| 68 | // file. Ideallly, we would include this information in D-Bus's GetStatus |
| 69 | // method and UpdateStatus signal. A potential issue is that update_engine may |
| 70 | // be unresponsive during an update download. |
| 71 | utils::WriteFile(kDeadlineFile, |
| 72 | response.deadline.data(), |
| 73 | response.deadline.size()); |
| 74 | chmod(kDeadlineFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
| 75 | |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 76 | completer.set_code(kActionCodeSuccess); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, |
| 80 | std::string* install_dev) { |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 81 | TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/")); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 82 | string ret(boot_dev); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 83 | string::reverse_iterator it = ret.rbegin(); // last character in string |
| 84 | // Right now, we just switch '3' and '5' partition numbers. |
| 85 | TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5')); |
| 86 | *it = (*it == '3') ? '5' : '3'; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 87 | *install_dev = ret; |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | } // namespace chromeos_update_engine |