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 got_no_update_response_ = true; |
26 LOG(INFO) << "There are no updates. Aborting."; | 26 LOG(INFO) << "There are no updates. Aborting."; |
27 return; | 27 return; |
28 } | 28 } |
29 InstallPlan install_plan; | 29 install_plan_.download_url = response.codebase; |
30 install_plan.download_url = response.codebase; | 30 install_plan_.size = response.size; |
31 install_plan.download_hash = response.hash; | 31 install_plan_.download_hash = response.hash; |
32 TEST_AND_RETURN(GetInstallDev( | 32 TEST_AND_RETURN(GetInstallDev( |
33 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), | 33 (!boot_device_.empty() ? boot_device_ : utils::BootDevice()), |
34 &install_plan.install_path)); | 34 &install_plan_.install_path)); |
35 install_plan.kernel_install_path = | 35 install_plan_.kernel_install_path = |
36 utils::BootKernelDevice(install_plan.install_path); | 36 utils::BootKernelDevice(install_plan_.install_path); |
37 | 37 |
38 // Get the filename part of the url. Assume that if it has kFullUpdateTag | 38 install_plan_.is_full_update = true; // TODO(adlr): know if update is a delta |
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 | 39 |
48 if (filename.size() > 255) { | |
49 // Very long name. Let's shorten it | |
50 filename.resize(255); | |
51 } | |
52 TEST_AND_RETURN(HasOutputPipe()); | 40 TEST_AND_RETURN(HasOutputPipe()); |
53 if (HasOutputPipe()) | 41 if (HasOutputPipe()) |
54 SetOutputObject(install_plan); | 42 SetOutputObject(install_plan_); |
55 LOG(INFO) << "Using this install plan:"; | 43 LOG(INFO) << "Using this install plan:"; |
56 install_plan.Dump(); | 44 install_plan_.Dump(); |
57 | 45 |
58 completer.set_success(true); | 46 completer.set_success(true); |
59 } | 47 } |
60 | 48 |
61 bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, | 49 bool OmahaResponseHandlerAction::GetInstallDev(const std::string& boot_dev, |
62 std::string* install_dev) { | 50 std::string* install_dev) { |
63 TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/")); | 51 TEST_AND_RETURN_FALSE(utils::StringHasPrefix(boot_dev, "/dev/")); |
64 string ret(boot_dev); | 52 string ret(boot_dev); |
65 string::reverse_iterator it = ret.rbegin(); // last character in string | 53 string::reverse_iterator it = ret.rbegin(); // last character in string |
66 // Right now, we just switch '3' and '5' partition numbers. | 54 // Right now, we just switch '3' and '5' partition numbers. |
67 TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5')); | 55 TEST_AND_RETURN_FALSE((*it == '3') || (*it == '5')); |
68 *it = (*it == '3') ? '5' : '3'; | 56 *it = (*it == '3') ? '5' : '3'; |
69 *install_dev = ret; | 57 *install_dev = ret; |
70 return true; | 58 return true; |
71 } | 59 } |
72 | 60 |
73 } // namespace chromeos_update_engine | 61 } // namespace chromeos_update_engine |
OLD | NEW |