OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "update_engine/omaha_response_handler_action.h" | 5 #include "update_engine/omaha_response_handler_action.h" |
6 #include <string> | 6 #include <string> |
7 #include "update_engine/utils.h" | 7 #include "update_engine/utils.h" |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
11 namespace chromeos_update_engine { | 11 namespace chromeos_update_engine { |
12 | 12 |
13 namespace { | 13 namespace { |
14 // If the file part of the download URL contains kFullUpdateTag, then and | 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 | 15 // only then do we assume it's a full update. Otherwise, we assume it's a |
16 // delta update. | 16 // delta update. |
17 const string kFullUpdateTag = "_FULL_"; | 17 const string kFullUpdateTag = "_FULL_"; |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 void OmahaResponseHandlerAction::PerformAction() { | 20 void OmahaResponseHandlerAction::PerformAction() { |
21 CHECK(HasInputObject()); | 21 CHECK(HasInputObject()); |
22 ScopedActionCompleter completer(processor_, this); | 22 ScopedActionCompleter completer(processor_, this); |
23 const UpdateCheckResponse& response = GetInputObject(); | 23 const UpdateCheckResponse& response = GetInputObject(); |
24 if (!response.update_exists) { | 24 if (!response.update_exists) { |
| 25 got_no_update_response_ = true; |
25 LOG(INFO) << "There are no updates. Aborting."; | 26 LOG(INFO) << "There are no updates. Aborting."; |
26 return; | 27 return; |
27 } | 28 } |
28 InstallPlan install_plan; | 29 InstallPlan install_plan; |
29 install_plan.download_url = response.codebase; | 30 install_plan.download_url = response.codebase; |
30 install_plan.download_hash = response.hash; | 31 install_plan.download_hash = response.hash; |
31 TEST_AND_RETURN(GetInstallDev( | 32 TEST_AND_RETURN(GetInstallDev( |
32 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), | 33 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), |
33 &install_plan.install_path)); | 34 &install_plan.install_path)); |
34 | 35 |
35 // Get the filename part of the url. Assume that if it has kFullUpdateTag | 36 // Get the filename part of the url. Assume that if it has kFullUpdateTag |
36 // in the name, it's a full update. | 37 // in the name, it's a full update. |
37 string::size_type last_slash = response.codebase.rfind('/'); | 38 string::size_type last_slash = response.codebase.rfind('/'); |
38 string filename; | 39 string filename; |
39 if (last_slash == string::npos) | 40 if (last_slash == string::npos) |
40 filename = response.codebase; | 41 filename = response.codebase; |
41 else | 42 else |
42 filename = response.codebase.substr(last_slash + 1); | 43 filename = response.codebase.substr(last_slash + 1); |
43 install_plan.is_full_update = (filename.find(kFullUpdateTag) != string::npos); | 44 install_plan.is_full_update = (filename.find(kFullUpdateTag) != string::npos); |
44 | 45 |
45 if (filename.size() > 255) { | 46 if (filename.size() > 255) { |
46 // Very long name. Let's shorten it | 47 // Very long name. Let's shorten it |
47 filename.resize(255); | 48 filename.resize(255); |
48 } | 49 } |
49 // TODO(adlr): come up with a better place to download to: | 50 // TODO(adlr): come up with a better place to download to: |
50 install_plan.download_path = utils::kStatefulPartition + "/" + filename; | 51 install_plan.download_path = string(utils::kStatefulPartition) + "/" + |
| 52 filename; |
51 if (HasOutputPipe()) | 53 if (HasOutputPipe()) |
52 SetOutputObject(install_plan); | 54 SetOutputObject(install_plan); |
53 LOG(INFO) << "Using this install plan:"; | 55 LOG(INFO) << "Using this install plan:"; |
54 install_plan.Dump(); | 56 install_plan.Dump(); |
55 completer.set_success(true); | 57 completer.set_success(true); |
56 } | 58 } |
57 | 59 |
58 bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, | 60 bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, |
59 std::string* install_dev) { | 61 std::string* install_dev) { |
60 TEST_AND_RETURN_FALSE(!boot_dev.empty()); | 62 TEST_AND_RETURN_FALSE(!boot_dev.empty()); |
61 string ret(boot_dev); | 63 string ret(boot_dev); |
62 char last_char = *ret.rbegin(); | 64 char last_char = *ret.rbegin(); |
63 TEST_AND_RETURN_FALSE((last_char >= '0') && (last_char <= '9')); | 65 TEST_AND_RETURN_FALSE((last_char >= '0') && (last_char <= '9')); |
64 // Chop off last char | 66 // Chop off last char |
65 ret.resize(ret.size() - 1); | 67 ret.resize(ret.size() - 1); |
66 // If last_char is odd (1 or 3), increase it, otherwise decrease | 68 // If last_char is odd (1 or 3), increase it, otherwise decrease |
67 if (last_char % 2) | 69 if (last_char % 2) |
68 last_char++; | 70 last_char++; |
69 else | 71 else |
70 last_char--; | 72 last_char--; |
71 ret += last_char; | 73 ret += last_char; |
72 *install_dev = ret; | 74 *install_dev = ret; |
73 return true; | 75 return true; |
74 } | 76 } |
75 | 77 |
76 } // namespace chromeos_update_engine | 78 } // namespace chromeos_update_engine |
OLD | NEW |