| 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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/memory_mapped_file.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 | |
| 13 #include "courgette/crc.h" | 13 #include "courgette/crc.h" |
| 14 #include "courgette/region.h" | 14 #include "courgette/region.h" |
| 15 #include "courgette/streams.h" | 15 #include "courgette/streams.h" |
| 16 #include "courgette/simple_delta.h" | 16 #include "courgette/simple_delta.h" |
| 17 #include "courgette/patcher_x86_32.h" | 17 #include "courgette/patcher_x86_32.h" |
| 18 | 18 |
| 19 namespace courgette { | 19 namespace courgette { |
| 20 | 20 |
| 21 // EnsemblePatchApplication is all the logic and data required to apply the | 21 // EnsemblePatchApplication is all the logic and data required to apply the |
| 22 // multi-stage patch. | 22 // multi-stage patch. |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 371 |
| 372 return C_OK; | 372 return C_OK; |
| 373 } | 373 } |
| 374 | 374 |
| 375 Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, | 375 Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, |
| 376 const base::FilePath::CharType* patch_file_name, | 376 const base::FilePath::CharType* patch_file_name, |
| 377 const base::FilePath::CharType* new_file_name) { | 377 const base::FilePath::CharType* new_file_name) { |
| 378 // First read enough of the patch file to validate the header is well-formed. | 378 // First read enough of the patch file to validate the header is well-formed. |
| 379 // A few varint32 numbers should fit in 100. | 379 // A few varint32 numbers should fit in 100. |
| 380 base::FilePath patch_file_path(patch_file_name); | 380 base::FilePath patch_file_path(patch_file_name); |
| 381 file_util::MemoryMappedFile patch_file; | 381 base::MemoryMappedFile patch_file; |
| 382 if (!patch_file.Initialize(patch_file_path)) | 382 if (!patch_file.Initialize(patch_file_path)) |
| 383 return C_READ_OPEN_ERROR; | 383 return C_READ_OPEN_ERROR; |
| 384 | 384 |
| 385 // 'Dry-run' the first step of the patch process to validate format of header. | 385 // 'Dry-run' the first step of the patch process to validate format of header. |
| 386 SourceStream patch_header_stream; | 386 SourceStream patch_header_stream; |
| 387 patch_header_stream.Init(patch_file.data(), patch_file.length()); | 387 patch_header_stream.Init(patch_file.data(), patch_file.length()); |
| 388 EnsemblePatchApplication patch_process; | 388 EnsemblePatchApplication patch_process; |
| 389 Status status = patch_process.ReadHeader(&patch_header_stream); | 389 Status status = patch_process.ReadHeader(&patch_header_stream); |
| 390 if (status != C_OK) | 390 if (status != C_OK) |
| 391 return status; | 391 return status; |
| 392 | 392 |
| 393 // Read the old_file. | 393 // Read the old_file. |
| 394 base::FilePath old_file_path(old_file_name); | 394 base::FilePath old_file_path(old_file_name); |
| 395 file_util::MemoryMappedFile old_file; | 395 base::MemoryMappedFile old_file; |
| 396 if (!old_file.Initialize(old_file_path)) | 396 if (!old_file.Initialize(old_file_path)) |
| 397 return C_READ_ERROR; | 397 return C_READ_ERROR; |
| 398 | 398 |
| 399 // Apply patch on streams. | 399 // Apply patch on streams. |
| 400 SourceStream old_source_stream; | 400 SourceStream old_source_stream; |
| 401 SourceStream patch_source_stream; | 401 SourceStream patch_source_stream; |
| 402 old_source_stream.Init(old_file.data(), old_file.length()); | 402 old_source_stream.Init(old_file.data(), old_file.length()); |
| 403 patch_source_stream.Init(patch_file.data(), patch_file.length()); | 403 patch_source_stream.Init(patch_file.data(), patch_file.length()); |
| 404 SinkStream new_sink_stream; | 404 SinkStream new_sink_stream; |
| 405 status = ApplyEnsemblePatch(&old_source_stream, &patch_source_stream, | 405 status = ApplyEnsemblePatch(&old_source_stream, &patch_source_stream, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 416 static_cast<int>(new_sink_stream.Length())); | 416 static_cast<int>(new_sink_stream.Length())); |
| 417 if (written == -1) | 417 if (written == -1) |
| 418 return C_WRITE_OPEN_ERROR; | 418 return C_WRITE_OPEN_ERROR; |
| 419 if (static_cast<size_t>(written) != new_sink_stream.Length()) | 419 if (static_cast<size_t>(written) != new_sink_stream.Length()) |
| 420 return C_WRITE_ERROR; | 420 return C_WRITE_ERROR; |
| 421 | 421 |
| 422 return C_OK; | 422 return C_OK; |
| 423 } | 423 } |
| 424 | 424 |
| 425 } // namespace | 425 } // namespace |
| OLD | NEW |