blob: f90255a9db0684ebdc40f90efe1f592d32a2db70 [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);
23 const UpdateCheckResponse& response = GetInputObject();
24 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 }
29 InstallPlan install_plan;
30 install_plan.download_url = response.codebase;
31 install_plan.download_hash = response.hash;
32 TEST_AND_RETURN(GetInstallDev(
33 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()),
34 &install_plan.install_path));
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070035 install_plan.kernel_install_path =
36 utils::BootKernelDevice(install_plan.install_path);
adlr@google.com3defe6a2009-12-04 20:57:17 +000037
38 // Get the filename part of the url. Assume that if it has kFullUpdateTag
39 // in the name, it's a full update.
40 string::size_type last_slash = response.codebase.rfind('/');
41 string filename;
42 if (last_slash == string::npos)
43 filename = response.codebase;
44 else
45 filename = response.codebase.substr(last_slash + 1);
46 install_plan.is_full_update = (filename.find(kFullUpdateTag) != string::npos);
47
48 if (filename.size() > 255) {
49 // Very long name. Let's shorten it
50 filename.resize(255);
51 }
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070052 TEST_AND_RETURN(HasOutputPipe());
adlr@google.com3defe6a2009-12-04 20:57:17 +000053 if (HasOutputPipe())
54 SetOutputObject(install_plan);
55 LOG(INFO) << "Using this install plan:";
56 install_plan.Dump();
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070057
adlr@google.com3defe6a2009-12-04 20:57:17 +000058 completer.set_success(true);
59}
60
61bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev,
62 std::string* install_dev) {
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070063 TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/"));
adlr@google.com3defe6a2009-12-04 20:57:17 +000064 string ret(boot_dev);
Andrew de los Reyesf98bff82010-05-06 13:33:25 -070065 string::reverse_iterator it = ret.rbegin(); // last character in string
66 // Right now, we just switch '3' and '5' partition numbers.
67 TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5'));
68 *it = (*it == '3') ? '5' : '3';
adlr@google.com3defe6a2009-12-04 20:57:17 +000069 *install_dev = ret;
70 return true;
71}
72
73} // namespace chromeos_update_engine