adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 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" |
| 6 | #include <string> |
| 7 | #include "update_engine/utils.h" |
| 8 | |
| 9 | using std::string; |
| 10 | |
| 11 | namespace chromeos_update_engine { |
| 12 | |
| 13 | namespace { |
| 14 | // If the file part of the download URL contains kFullUpdateTag, then and |
| 15 | // only then do we assume it's a full update. Otherwise, we assume it's a |
| 16 | // delta update. |
| 17 | const string kFullUpdateTag = "_FULL_"; |
| 18 | } // namespace |
| 19 | |
| 20 | void OmahaResponseHandlerAction::PerformAction() { |
| 21 | CHECK(HasInputObject()); |
| 22 | ScopedActionCompleter completer(processor_, this); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 23 | const OmahaResponse& response = GetInputObject(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 24 | if (!response.update_exists) { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 25 | got_no_update_response_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 26 | LOG(INFO) << "There are no updates. Aborting."; |
| 27 | return; |
| 28 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 29 | install_plan_.download_url = response.codebase; |
| 30 | install_plan_.size = response.size; |
| 31 | install_plan_.download_hash = response.hash; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 32 | TEST_AND_RETURN(GetInstallDev( |
| 33 | (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 34 | &install_plan_.install_path)); |
| 35 | install_plan_.kernel_install_path = |
| 36 | utils::BootKernelDevice(install_plan_.install_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 38 | install_plan_.is_full_update = !response.is_delta; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 39 | |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 40 | TEST_AND_RETURN(HasOutputPipe()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 41 | if (HasOutputPipe()) |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 42 | SetOutputObject(install_plan_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | LOG(INFO) << "Using this install plan:"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 44 | install_plan_.Dump(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 45 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | completer.set_success(true); |
| 47 | } |
| 48 | |
| 49 | bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, |
| 50 | std::string* install_dev) { |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 51 | TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/")); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | string ret(boot_dev); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 53 | string::reverse_iterator it = ret.rbegin(); // last character in string |
| 54 | // Right now, we just switch '3' and '5' partition numbers. |
| 55 | TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5')); |
| 56 | *it = (*it == '3') ? '5' : '3'; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 57 | *install_dev = ret; |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | } // namespace chromeos_update_engine |