| OLD | NEW |
| 1 // Copyright (c) 2010 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/logging.h" | 11 #include "base/logging.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return C_READ_ERROR; | 389 return C_READ_ERROR; |
| 390 | 390 |
| 391 // Apply patch on streams. | 391 // Apply patch on streams. |
| 392 SourceStream old_source_stream; | 392 SourceStream old_source_stream; |
| 393 SourceStream patch_source_stream; | 393 SourceStream patch_source_stream; |
| 394 old_source_stream.Init(old_file.data(), old_file.length()); | 394 old_source_stream.Init(old_file.data(), old_file.length()); |
| 395 patch_source_stream.Init(patch_file.data(), patch_file.length()); | 395 patch_source_stream.Init(patch_file.data(), patch_file.length()); |
| 396 SinkStream new_sink_stream; | 396 SinkStream new_sink_stream; |
| 397 status = ApplyEnsemblePatch(&old_source_stream, &patch_source_stream, | 397 status = ApplyEnsemblePatch(&old_source_stream, &patch_source_stream, |
| 398 &new_sink_stream); | 398 &new_sink_stream); |
| 399 if (status != C_OK) |
| 400 return status; |
| 399 | 401 |
| 400 // Write the patched data to |new_file_name|. | 402 // Write the patched data to |new_file_name|. |
| 401 FilePath new_file_path(new_file_name); | 403 FilePath new_file_path(new_file_name); |
| 402 int written = | 404 int written = |
| 403 file_util::WriteFile( | 405 file_util::WriteFile( |
| 404 new_file_path, | 406 new_file_path, |
| 405 reinterpret_cast<const char*>(new_sink_stream.Buffer()), | 407 reinterpret_cast<const char*>(new_sink_stream.Buffer()), |
| 406 static_cast<int>(new_sink_stream.Length())); | 408 static_cast<int>(new_sink_stream.Length())); |
| 407 if (written == -1) | 409 if (written == -1) |
| 408 return C_WRITE_OPEN_ERROR; | 410 return C_WRITE_OPEN_ERROR; |
| 409 if (static_cast<size_t>(written) != new_sink_stream.Length()) | 411 if (static_cast<size_t>(written) != new_sink_stream.Length()) |
| 410 return C_WRITE_ERROR; | 412 return C_WRITE_ERROR; |
| 411 | 413 |
| 412 return C_OK; | 414 return C_OK; |
| 413 } | 415 } |
| 414 | 416 |
| 415 } // namespace | 417 } // namespace |
| OLD | NEW |