OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains the code to apply a Courgette patch. | 5 // This file contains the code to apply a Courgette patch. |
6 | 6 |
7 #include "courgette/ensemble.h" | 7 #include "courgette/ensemble.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ensemble_correction, output); | 374 ensemble_correction, output); |
375 if (status != C_OK) | 375 if (status != C_OK) |
376 return status; | 376 return status; |
377 | 377 |
378 return C_OK; | 378 return C_OK; |
379 } | 379 } |
380 | 380 |
381 Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, | 381 Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, |
382 const base::FilePath::CharType* patch_file_name, | 382 const base::FilePath::CharType* patch_file_name, |
383 const base::FilePath::CharType* new_file_name) { | 383 const base::FilePath::CharType* new_file_name) { |
384 // First read enough of the patch file to validate the header is well-formed. | |
385 // A few varint32 numbers should fit in 100. | |
386 base::FilePath patch_file_path(patch_file_name); | 384 base::FilePath patch_file_path(patch_file_name); |
387 base::MemoryMappedFile patch_file; | 385 base::MemoryMappedFile patch_file; |
388 if (!patch_file.Initialize(patch_file_path)) | 386 if (!patch_file.Initialize(patch_file_path)) |
389 return C_READ_OPEN_ERROR; | 387 return C_READ_OPEN_ERROR; |
390 | 388 |
391 // 'Dry-run' the first step of the patch process to validate format of header. | 389 // 'Dry-run' the first step of the patch process to validate format of header. |
392 SourceStream patch_header_stream; | 390 SourceStream patch_header_stream; |
393 patch_header_stream.Init(patch_file.data(), patch_file.length()); | 391 patch_header_stream.Init(patch_file.data(), patch_file.length()); |
394 EnsemblePatchApplication patch_process; | 392 EnsemblePatchApplication patch_process; |
395 Status status = patch_process.ReadHeader(&patch_header_stream); | 393 Status status = patch_process.ReadHeader(&patch_header_stream); |
(...skipping 26 matching lines...) Expand all Loading... |
422 static_cast<int>(new_sink_stream.Length())); | 420 static_cast<int>(new_sink_stream.Length())); |
423 if (written == -1) | 421 if (written == -1) |
424 return C_WRITE_OPEN_ERROR; | 422 return C_WRITE_OPEN_ERROR; |
425 if (static_cast<size_t>(written) != new_sink_stream.Length()) | 423 if (static_cast<size_t>(written) != new_sink_stream.Length()) |
426 return C_WRITE_ERROR; | 424 return C_WRITE_ERROR; |
427 | 425 |
428 return C_OK; | 426 return C_OK; |
429 } | 427 } |
430 | 428 |
431 } // namespace | 429 } // namespace |
OLD | NEW |