blob: d3142a7eaf8759494ca601c119315d20367287f4 [file] [log] [blame]
Darin Petkov73058b42010-10-06 16:32:19 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// 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 Petkov73058b42010-10-06 16:32:19 -07006
adlr@google.com3defe6a2009-12-04 20:57:17 +00007#include <string>
Darin Petkov73058b42010-10-06 16:32:19 -07008
9#include <base/logging.h>
10
Darin Petkov0406e402010-10-06 21:33:11 -070011#include "update_engine/delta_performer.h"
Darin Petkov73058b42010-10-06 16:32:19 -070012#include "update_engine/prefs_interface.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000013#include "update_engine/utils.h"
14
15using std::string;
16
17namespace chromeos_update_engine {
18
adlr@google.com3defe6a2009-12-04 20:57:17 +000019void OmahaResponseHandlerAction::PerformAction() {
20 CHECK(HasInputObject());
21 ScopedActionCompleter completer(processor_, this);
Darin Petkov6a5b3222010-07-13 14:55:28 -070022 const OmahaResponse& response = GetInputObject();
adlr@google.com3defe6a2009-12-04 20:57:17 +000023 if (!response.update_exists) {
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080024 got_no_update_response_ = true;
adlr@google.com3defe6a2009-12-04 20:57:17 +000025 LOG(INFO) << "There are no updates. Aborting.";
26 return;
27 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070028 install_plan_.download_url = response.codebase;
29 install_plan_.size = response.size;
30 install_plan_.download_hash = response.hash;
Darin Petkov0406e402010-10-06 21:33:11 -070031
32 install_plan_.is_resume =
33 DeltaPerformer::CanResumeUpdate(prefs_, response.hash);
34 if (!install_plan_.is_resume) {
35 LOG_IF(WARNING, !DeltaPerformer::ResetUpdateProgress(prefs_))
36 << "Unable to reset the update progress.";
37 LOG_IF(WARNING, !prefs_->SetString(kPrefsUpdateCheckResponseHash,
38 response.hash))
39 << "Unable to save the update check response hash.";
40 }
41
adlr@google.com3defe6a2009-12-04 20:57:17 +000042 TEST_AND_RETURN(GetInstallDev(
43 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()),
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070044 &install_plan_.install_path));
45 install_plan_.kernel_install_path =
46 utils::BootKernelDevice(install_plan_.install_path);
adlr@google.com3defe6a2009-12-04 20:57:17 +000047
Andrew de los Reyes3270f742010-07-15 22:28:14 -070048 install_plan_.is_full_update = !response.is_delta;
adlr@google.com3defe6a2009-12-04 20:57:17 +000049
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070050 TEST_AND_RETURN(HasOutputPipe());
adlr@google.com3defe6a2009-12-04 20:57:17 +000051 if (HasOutputPipe())
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070052 SetOutputObject(install_plan_);
adlr@google.com3defe6a2009-12-04 20:57:17 +000053 LOG(INFO) << "Using this install plan:";
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070054 install_plan_.Dump();
Darin Petkov6a5b3222010-07-13 14:55:28 -070055
Darin Petkovc1a8b422010-07-19 11:34:49 -070056 completer.set_code(kActionCodeSuccess);
adlr@google.com3defe6a2009-12-04 20:57:17 +000057}
58
59bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev,
60 std::string* install_dev) {
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070061 TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/"));
adlr@google.com3defe6a2009-12-04 20:57:17 +000062 string ret(boot_dev);
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070063 string::reverse_iterator it = ret.rbegin(); // last character in string
64 // Right now, we just switch '3' and '5' partition numbers.
65 TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5'));
66 *it = (*it == '3') ? '5' : '3';
adlr@google.com3defe6a2009-12-04 20:57:17 +000067 *install_dev = ret;
68 return true;
69}
70
71} // namespace chromeos_update_engine