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

Side by Side Diff: courgette/third_party/bsdiff/bsdiff_apply.cc

Issue 2534873005: Sandbox the component updater's patcher utility process. (Closed)
Patch Set: Through #14 Created 4 years 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
OLDNEW
1 // Copyright 2003, 2004 Colin Percival 1 // Copyright 2003, 2004 Colin Percival
2 // All rights reserved 2 // All rights reserved
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted providing that the following conditions 5 // modification, are permitted providing that the following conditions
6 // are met: 6 // are met:
7 // 1. Redistributions of source code must retain the above copyright 7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright 9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the 10 // notice, this list of conditions and the following disclaimer in the
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return UNEXPECTED_ERROR; 182 return UNEXPECTED_ERROR;
183 183
184 if (CalculateCrc(old_start, old_size) != header.scrc32) 184 if (CalculateCrc(old_start, old_size) != header.scrc32)
185 return CRC_ERROR; 185 return CRC_ERROR;
186 186
187 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); 187 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream);
188 188
189 return OK; 189 return OK;
190 } 190 }
191 191
192 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path, 192 BSDiffStatus ApplyBinaryPatch(base::File old_file,
193 const base::FilePath& patch_file_path, 193 base::File patch_file,
194 const base::FilePath& new_file_path) { 194 base::File new_file) {
195 // Set up the old stream. 195 // Set up the old stream.
196 base::MemoryMappedFile old_file; 196 base::MemoryMappedFile old_file_mem;
197 if (!old_file.Initialize(old_file_path)) { 197 if (!old_file_mem.Initialize(std::move(old_file))) {
198 return READ_ERROR; 198 return READ_ERROR;
199 } 199 }
200 SourceStream old_file_stream; 200 SourceStream old_file_stream;
201 old_file_stream.Init(old_file.data(), old_file.length()); 201 old_file_stream.Init(old_file_mem.data(), old_file_mem.length());
202 202
203 // Set up the patch stream. 203 // Set up the patch stream.
204 base::MemoryMappedFile patch_file; 204 base::MemoryMappedFile patch_file_mem;
205 if (!patch_file.Initialize(patch_file_path)) { 205 if (!patch_file_mem.Initialize(std::move(patch_file))) {
206 return READ_ERROR; 206 return READ_ERROR;
207 } 207 }
208 SourceStream patch_file_stream; 208 SourceStream patch_file_stream;
209 patch_file_stream.Init(patch_file.data(), patch_file.length()); 209 patch_file_stream.Init(patch_file_mem.data(), patch_file_mem.length());
210 210
211 // Set up the new stream and apply the patch. 211 // Set up the new stream and apply the patch.
212 SinkStream new_sink_stream; 212 SinkStream new_sink_stream;
213 BSDiffStatus status = 213 BSDiffStatus status =
214 ApplyBinaryPatch(&old_file_stream, &patch_file_stream, &new_sink_stream); 214 ApplyBinaryPatch(&old_file_stream, &patch_file_stream, &new_sink_stream);
215 if (status != OK) { 215 if (status != OK) {
216 return status; 216 return status;
217 } 217 }
218 218
219 // Write the stream to disk. 219 // Write the stream to disk.
220 int written = base::WriteFile( 220 int written = new_file.Write(
221 new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), 221 0,
222 reinterpret_cast<const char*>(new_sink_stream.Buffer()),
222 static_cast<int>(new_sink_stream.Length())); 223 static_cast<int>(new_sink_stream.Length()));
223 if (written != static_cast<int>(new_sink_stream.Length())) 224 if (written != static_cast<int>(new_sink_stream.Length()))
224 return WRITE_ERROR; 225 return WRITE_ERROR;
225 return OK; 226 return OK;
226 } 227 }
227 228
229 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path,
230 const base::FilePath& patch_file_path,
231 const base::FilePath& new_file_path) {
232 return ApplyBinaryPatch(
233 base::File(
234 base::FilePath(old_file_path),
235 base::File::FLAG_OPEN | base::File::FLAG_READ),
236 base::File(
237 base::FilePath(patch_file_path),
238 base::File::FLAG_OPEN | base::File::FLAG_READ),
239 base::File(
240 base::FilePath(new_file_path),
241 base::File::FLAG_CREATE_ALWAYS |
242 base::File::FLAG_WRITE |
243 base::File::FLAG_EXCLUSIVE_WRITE));
244 }
245
228 } // namespace bsdiff 246 } // namespace bsdiff
OLDNEW
« courgette/third_party/bsdiff/bsdiff.h ('K') | « courgette/third_party/bsdiff/bsdiff.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698