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