Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: download_action.cc

Issue 3712003: AU: Verify source rootfs/kernel hashes before applying delta. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: verify source partitions only for new updates Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « delta_performer_unittest.cc ('k') | filesystem_copier_action.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 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> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include <glib.h> 10 #include <glib.h>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 rootfs_buffered_file_writer_.get())); 57 rootfs_buffered_file_writer_.get()));
58 split_file_writer_->SetFirstOpenArgs( 58 split_file_writer_->SetFirstOpenArgs(
59 install_plan_.kernel_install_path.c_str(), 59 install_plan_.kernel_install_path.c_str(),
60 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 60 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE,
61 0644); 61 0644);
62 decompressing_file_writer_.reset( 62 decompressing_file_writer_.reset(
63 new GzipDecompressingFileWriter(split_file_writer_.get())); 63 new GzipDecompressingFileWriter(split_file_writer_.get()));
64 writer_ = decompressing_file_writer_.get(); 64 writer_ = decompressing_file_writer_.get();
65 } else { 65 } else {
66 delta_performer_.reset(new DeltaPerformer(prefs_)); 66 delta_performer_.reset(new DeltaPerformer(prefs_));
67 delta_performer_->set_current_kernel_hash(
68 &install_plan_.current_kernel_hash);
69 delta_performer_->set_current_rootfs_hash(
70 &install_plan_.current_rootfs_hash);
67 writer_ = delta_performer_.get(); 71 writer_ = delta_performer_.get();
68 } 72 }
69 } 73 }
70 int rc = writer_->Open(install_plan_.install_path.c_str(), 74 int rc = writer_->Open(install_plan_.install_path.c_str(),
71 O_TRUNC | O_WRONLY | O_CREAT | O_LARGEFILE, 75 O_TRUNC | O_WRONLY | O_CREAT | O_LARGEFILE,
72 0644); 76 0644);
73 if (rc < 0) { 77 if (rc < 0) {
74 LOG(ERROR) << "Unable to open output file " << install_plan_.install_path; 78 LOG(ERROR) << "Unable to open output file " << install_plan_.install_path;
75 // report error to processor 79 // report error to processor
76 processor_->ActionComplete(this, kActionCodeInstallDeviceOpenError); 80 processor_->ActionComplete(this, kActionCodeInstallDeviceOpenError);
77 return; 81 return;
78 } 82 }
79 if (!install_plan_.is_full_update) { 83 if (!install_plan_.is_full_update) {
80 if (!delta_performer_->OpenKernel( 84 if (!delta_performer_->OpenKernel(
81 install_plan_.kernel_install_path.c_str())) { 85 install_plan_.kernel_install_path.c_str())) {
82 LOG(ERROR) << "Unable to open kernel file " 86 LOG(ERROR) << "Unable to open kernel file "
83 << install_plan_.kernel_install_path.c_str(); 87 << install_plan_.kernel_install_path.c_str();
84 writer_->Close(); 88 writer_->Close();
85 processor_->ActionComplete(this, kActionCodeKernelDeviceOpenError); 89 processor_->ActionComplete(this, kActionCodeKernelDeviceOpenError);
86 return; 90 return;
87 } 91 }
88 } 92 }
89 if (delegate_) { 93 if (delegate_) {
90 delegate_->SetDownloadStatus(true); // Set to active. 94 delegate_->SetDownloadStatus(true); // Set to active.
91 } 95 }
92 http_fetcher_->BeginTransfer(install_plan_.download_url); 96 http_fetcher_->BeginTransfer(install_plan_.download_url);
93 } 97 }
94 98
95 void DownloadAction::TerminateProcessing() { 99 void DownloadAction::TerminateProcessing() {
96 CHECK(writer_); 100 if (writer_) {
97 CHECK_EQ(writer_->Close(), 0); 101 LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer.";
98 writer_ = NULL; 102 writer_ = NULL;
103 }
99 http_fetcher_->TerminateTransfer(); 104 http_fetcher_->TerminateTransfer();
100 if (delegate_) { 105 if (delegate_) {
101 delegate_->SetDownloadStatus(false); // Set to inactive. 106 delegate_->SetDownloadStatus(false); // Set to inactive.
102 } 107 }
103 } 108 }
104 109
105 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, 110 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher,
106 const char* bytes, 111 const char* bytes,
107 int length) { 112 int length) {
108 bytes_received_ += length; 113 bytes_received_ += length;
109 if (delegate_) 114 if (delegate_)
110 delegate_->BytesReceived(bytes_received_, install_plan_.size); 115 delegate_->BytesReceived(bytes_received_, install_plan_.size);
111 int rc = writer_->Write(bytes, length); 116 if (writer_ && writer_->Write(bytes, length) < 0) {
112 TEST_AND_RETURN(rc >= 0); 117 LOG(ERROR) << "Write error -- terminating processing.";
118 TerminateProcessing();
119 processor_->ActionComplete(this, kActionCodeDownloadWriteError);
120 return;
121 }
113 omaha_hash_calculator_.Update(bytes, length); 122 omaha_hash_calculator_.Update(bytes, length);
114 } 123 }
115 124
116 namespace { 125 namespace {
117 void FlushLinuxCaches() { 126 void FlushLinuxCaches() {
118 vector<string> command; 127 vector<string> command;
119 command.push_back("/bin/sync"); 128 command.push_back("/bin/sync");
120 int rc; 129 int rc;
121 LOG(INFO) << "FlushLinuxCaches-sync..."; 130 LOG(INFO) << "FlushLinuxCaches-sync...";
122 Subprocess::SynchronousExec(command, &rc); 131 Subprocess::SynchronousExec(command, &rc);
123 LOG(INFO) << "FlushLinuxCaches-drop_caches..."; 132 LOG(INFO) << "FlushLinuxCaches-drop_caches...";
124 133
125 const char* const drop_cmd = "3\n"; 134 const char* const drop_cmd = "3\n";
126 utils::WriteFile("/proc/sys/vm/drop_caches", drop_cmd, strlen(drop_cmd)); 135 utils::WriteFile("/proc/sys/vm/drop_caches", drop_cmd, strlen(drop_cmd));
127 136
128 LOG(INFO) << "FlushLinuxCaches done."; 137 LOG(INFO) << "FlushLinuxCaches done.";
129 } 138 }
130 } 139 }
131 140
132 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { 141 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) {
133 if (writer_) { 142 if (writer_) {
134 CHECK_EQ(writer_->Close(), 0) << errno; 143 LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer.";
135 writer_ = NULL; 144 writer_ = NULL;
136 } 145 }
137 if (delegate_) { 146 if (delegate_) {
138 delegate_->SetDownloadStatus(false); // Set to inactive. 147 delegate_->SetDownloadStatus(false); // Set to inactive.
139 } 148 }
140 ActionExitCode code = 149 ActionExitCode code =
141 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError; 150 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError;
142 if (code == kActionCodeSuccess) { 151 if (code == kActionCodeSuccess) {
143 if (!install_plan_.is_full_update) { 152 if (!install_plan_.is_full_update) {
144 if (!delta_performer_->VerifyPayload("", 153 if (!delta_performer_->VerifyPayload("",
(...skipping 27 matching lines...) Expand all
172 181
173 FlushLinuxCaches(); 182 FlushLinuxCaches();
174 183
175 // Write the path to the output pipe if we're successful. 184 // Write the path to the output pipe if we're successful.
176 if (code == kActionCodeSuccess && HasOutputPipe()) 185 if (code == kActionCodeSuccess && HasOutputPipe())
177 SetOutputObject(GetInputObject()); 186 SetOutputObject(GetInputObject());
178 processor_->ActionComplete(this, code); 187 processor_->ActionComplete(this, code);
179 } 188 }
180 189
181 }; // namespace {} 190 }; // namespace {}
OLDNEW
« no previous file with comments | « delta_performer_unittest.cc ('k') | filesystem_copier_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698