blob: d93919a1bfde82a8590c8afd481d39b00049db34 [file] [log] [blame]
adlr@google.com3defe6a2009-12-04 20:57:17 +00001// 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
9using std::string;
10
11namespace chromeos_update_engine {
12
13namespace {
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.
17const string kFullUpdateTag = "_FULL_";
18} // namespace
19
20void OmahaResponseHandlerAction::PerformAction() {
21 CHECK(HasInputObject());
22 ScopedActionCompleter completer(processor_, this);
Darin Petkov6a5b3222010-07-13 14:55:28 -070023 const OmahaResponse& response = GetInputObject();
adlr@google.com3defe6a2009-12-04 20:57:17 +000024 if (!response.update_exists) {
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080025 got_no_update_response_ = true;
adlr@google.com3defe6a2009-12-04 20:57:17 +000026 LOG(INFO) << "There are no updates. Aborting.";
27 return;
28 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070029 install_plan_.download_url = response.codebase;
30 install_plan_.size = response.size;
31 install_plan_.download_hash = response.hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000032 TEST_AND_RETURN(GetInstallDev(
33 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()),
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070034 &install_plan_.install_path));
35 install_plan_.kernel_install_path =
36 utils::BootKernelDevice(install_plan_.install_path);
adlr@google.com3defe6a2009-12-04 20:57:17 +000037
Andrew de los Reyes3270f742010-07-15 22:28:14 -070038 install_plan_.is_full_update = !response.is_delta;
adlr@google.com3defe6a2009-12-04 20:57:17 +000039
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070040 TEST_AND_RETURN(HasOutputPipe());
adlr@google.com3defe6a2009-12-04 20:57:17 +000041 if (HasOutputPipe())
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070042 SetOutputObject(install_plan_);
adlr@google.com3defe6a2009-12-04 20:57:17 +000043 LOG(INFO) << "Using this install plan:";
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070044 install_plan_.Dump();
Darin Petkov6a5b3222010-07-13 14:55:28 -070045
adlr@google.com3defe6a2009-12-04 20:57:17 +000046 completer.set_success(true);
47}
48
49bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev,
50 std::string* install_dev) {
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070051 TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/"));
adlr@google.com3defe6a2009-12-04 20:57:17 +000052 string ret(boot_dev);
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070053 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.com3defe6a2009-12-04 20:57:17 +000057 *install_dev = ret;
58 return true;
59}
60
61} // namespace chromeos_update_engine