OLD | NEW |
1 /*- | 1 // Copyright 2003, 2004 Colin Percival |
2 * Copyright 2003,2004 Colin Percival | 2 // All rights reserved |
3 * All rights reserved | 3 // |
4 * | 4 // Redistribution and use in source and binary forms, with or without |
5 * Redistribution and use in source and binary forms, with or without | 5 // modification, are permitted providing that the following conditions |
6 * modification, are permitted providing that the following conditions | 6 // are met: |
7 * are met: | 7 // 1. Redistributions of source code must retain the above copyright |
8 * 1. Redistributions of source code must retain the above copyright | 8 // notice, this list of conditions and the following disclaimer. |
9 * notice, this list of conditions and the following disclaimer. | 9 // 2. Redistributions in binary form must reproduce the above copyright |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 // notice, this list of conditions and the following disclaimer in the |
11 * notice, this list of conditions and the following disclaimer in the | 11 // documentation and/or other materials provided with the distribution. |
12 * documentation and/or other materials provided with the distribution. | 12 // |
13 * | 13 // For the terms under which this work may be distributed, please see |
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 14 // the adjoining file "LICENSE". |
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 // |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 16 // bsdiff_apply.c -- Binary patch applier. |
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 17 // |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 18 // Changelog: |
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 19 // 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} |
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 20 // --Stephen Adams <sra@chromium.org> |
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 21 // 2013-04-10 - Add wrapper method to apply a patch to files directly. |
22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 22 // --Joshua Pawlicki <waffles@chromium.org> |
23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
24 * POSSIBILITY OF SUCH DAMAGE. | |
25 * | |
26 * Changelog: | |
27 * 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} | |
28 * --Stephen Adams <sra@chromium.org> | |
29 * 2013-04-10 - Add wrapper method to apply a patch to files directly. | |
30 * --Joshua Pawlicki <waffles@chromium.org> | |
31 */ | |
32 | 23 |
33 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 24 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
34 // Use of this source code is governed by a BSD-style license that can be | 25 // Use of this source code is governed by a BSD-style license that can be |
35 // found in the LICENSE file. | 26 // found in the LICENSE file. |
36 | 27 |
37 #include "courgette/third_party/bsdiff/bsdiff.h" | 28 #include "courgette/third_party/bsdiff/bsdiff.h" |
38 | 29 |
39 #include <stddef.h> | 30 #include <stddef.h> |
40 #include <stdint.h> | 31 #include <stdint.h> |
41 | 32 |
42 #include "base/files/memory_mapped_file.h" | 33 #include "base/files/memory_mapped_file.h" |
43 #include "courgette/crc.h" | 34 #include "courgette/crc.h" |
44 #include "courgette/streams.h" | 35 #include "courgette/streams.h" |
45 | 36 |
46 namespace courgette { | 37 namespace { |
| 38 |
| 39 using courgette::CalculateCrc; |
| 40 using courgette::SinkStream; |
| 41 using courgette::SinkStreamSet; |
| 42 using courgette::SourceStream; |
| 43 using courgette::SourceStreamSet; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 namespace bsdiff { |
47 | 48 |
48 BSDiffStatus MBS_ReadHeader(SourceStream* stream, MBSPatchHeader* header) { | 49 BSDiffStatus MBS_ReadHeader(SourceStream* stream, MBSPatchHeader* header) { |
49 if (!stream->Read(header->tag, sizeof(header->tag))) | 50 if (!stream->Read(header->tag, sizeof(header->tag))) |
50 return READ_ERROR; | 51 return READ_ERROR; |
51 if (!stream->ReadVarint32(&header->slen)) | 52 if (!stream->ReadVarint32(&header->slen)) |
52 return READ_ERROR; | 53 return READ_ERROR; |
53 if (!stream->ReadVarint32(&header->scrc32)) | 54 if (!stream->ReadVarint32(&header->scrc32)) |
54 return READ_ERROR; | 55 return READ_ERROR; |
55 if (!stream->ReadVarint32(&header->dlen)) | 56 if (!stream->ReadVarint32(&header->dlen)) |
56 return READ_ERROR; | 57 return READ_ERROR; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 208 |
208 // Write the stream to disk. | 209 // Write the stream to disk. |
209 int written = base::WriteFile( | 210 int written = base::WriteFile( |
210 new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), | 211 new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), |
211 static_cast<int>(new_sink_stream.Length())); | 212 static_cast<int>(new_sink_stream.Length())); |
212 if (written != static_cast<int>(new_sink_stream.Length())) | 213 if (written != static_cast<int>(new_sink_stream.Length())) |
213 return WRITE_ERROR; | 214 return WRITE_ERROR; |
214 return OK; | 215 return OK; |
215 } | 216 } |
216 | 217 |
217 } // namespace | 218 } // namespace bsdiff |
OLD | NEW |