OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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/download_action.h" | 5 #include "update_engine/download_action.h" |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> |
| 9 #include <vector> |
8 #include <glib.h> | 10 #include <glib.h> |
9 #include "update_engine/action_pipe.h" | 11 #include "update_engine/action_pipe.h" |
| 12 #include "update_engine/subprocess.h" |
10 | 13 |
11 using std::min; | 14 using std::min; |
| 15 using std::string; |
| 16 using std::vector; |
12 | 17 |
13 namespace chromeos_update_engine { | 18 namespace chromeos_update_engine { |
14 | 19 |
15 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) | 20 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) |
16 : writer_(NULL), | 21 : writer_(NULL), |
17 http_fetcher_(http_fetcher) {} | 22 http_fetcher_(http_fetcher) {} |
18 | 23 |
19 DownloadAction::~DownloadAction() {} | 24 DownloadAction::~DownloadAction() {} |
20 | 25 |
21 void DownloadAction::PerformAction() { | 26 void DownloadAction::PerformAction() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 82 } |
78 | 83 |
79 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, | 84 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, |
80 const char* bytes, | 85 const char* bytes, |
81 int length) { | 86 int length) { |
82 int rc = writer_->Write(bytes, length); | 87 int rc = writer_->Write(bytes, length); |
83 TEST_AND_RETURN(rc >= 0); | 88 TEST_AND_RETURN(rc >= 0); |
84 omaha_hash_calculator_.Update(bytes, length); | 89 omaha_hash_calculator_.Update(bytes, length); |
85 } | 90 } |
86 | 91 |
| 92 namespace { |
| 93 void FlushLinuxCaches() { |
| 94 vector<string> command; |
| 95 command.push_back("/bin/sync"); |
| 96 int rc; |
| 97 LOG(INFO) << "FlushLinuxCaches/sync..."; |
| 98 Subprocess::SynchronousExec(command, &rc); |
| 99 LOG(INFO) << "FlushLinuxCaches/drop_caches..."; |
| 100 |
| 101 const char* const drop_cmd = "3\n"; |
| 102 utils::WriteFile("/proc/sys/vm/drop_caches", drop_cmd, strlen(drop_cmd)); |
| 103 |
| 104 LOG(INFO) << "FlushLinuxCaches done."; |
| 105 } |
| 106 } |
| 107 |
87 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { | 108 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { |
88 if (writer_) { | 109 if (writer_) { |
89 CHECK_EQ(writer_->Close(), 0) << errno; | 110 CHECK_EQ(writer_->Close(), 0) << errno; |
90 writer_ = NULL; | 111 writer_ = NULL; |
91 } | 112 } |
92 if (successful) { | 113 if (successful) { |
93 // Make sure hash is correct | 114 // Make sure hash is correct |
94 omaha_hash_calculator_.Finalize(); | 115 omaha_hash_calculator_.Finalize(); |
95 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { | 116 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { |
96 LOG(ERROR) << "Download of " << install_plan_.download_url | 117 LOG(ERROR) << "Download of " << install_plan_.download_url |
97 << " failed. Expect hash " << install_plan_.download_hash | 118 << " failed. Expect hash " << install_plan_.download_hash |
98 << " but got hash " << omaha_hash_calculator_.hash(); | 119 << " but got hash " << omaha_hash_calculator_.hash(); |
99 successful = false; | 120 successful = false; |
100 } | 121 } |
101 } | 122 } |
| 123 |
| 124 FlushLinuxCaches(); |
102 | 125 |
103 // Write the path to the output pipe if we're successful | 126 // Write the path to the output pipe if we're successful |
104 if (successful && HasOutputPipe()) | 127 if (successful && HasOutputPipe()) |
105 SetOutputObject(GetInputObject()); | 128 SetOutputObject(GetInputObject()); |
106 processor_->ActionComplete(this, successful); | 129 processor_->ActionComplete(this, successful); |
107 } | 130 } |
108 | 131 |
109 }; // namespace {} | 132 }; // namespace {} |
OLD | NEW |