OLD | NEW |
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 SourceStream* control_stream_copy_counts = patch_streams.stream(0); | 90 SourceStream* control_stream_copy_counts = patch_streams.stream(0); |
91 SourceStream* control_stream_extra_counts = patch_streams.stream(1); | 91 SourceStream* control_stream_extra_counts = patch_streams.stream(1); |
92 SourceStream* control_stream_seeks = patch_streams.stream(2); | 92 SourceStream* control_stream_seeks = patch_streams.stream(2); |
93 SourceStream* diff_skips = patch_streams.stream(3); | 93 SourceStream* diff_skips = patch_streams.stream(3); |
94 SourceStream* diff_bytes = patch_streams.stream(4); | 94 SourceStream* diff_bytes = patch_streams.stream(4); |
95 SourceStream* extra_bytes = patch_streams.stream(5); | 95 SourceStream* extra_bytes = patch_streams.stream(5); |
96 | 96 |
97 const uint8_t* extra_start = extra_bytes->Buffer(); | 97 const uint8_t* extra_start = extra_bytes->Buffer(); |
98 const uint8_t* extra_end = extra_start + extra_bytes->Remaining(); | 98 const uint8_t* extra_end = extra_start + extra_bytes->Remaining(); |
99 const uint8_t* extra_position = extra_start; | 99 const uint8_t* extra_position = extra_start; |
| 100 extra_bytes->Skip(extra_bytes->Remaining()); |
100 | 101 |
101 const uint8_t* old_position = old_start; | 102 const uint8_t* old_position = old_start; |
102 | 103 |
103 if (header->dlen && !new_stream->Reserve(header->dlen)) | 104 if (header->dlen && !new_stream->Reserve(header->dlen)) |
104 return MEM_ERROR; | 105 return MEM_ERROR; |
105 | 106 |
106 uint32_t pending_diff_zeros = 0; | 107 uint32_t pending_diff_zeros = 0; |
107 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) | 108 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) |
108 return UNEXPECTED_ERROR; | 109 return UNEXPECTED_ERROR; |
109 | 110 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 179 |
179 const uint8_t* old_start = old_stream->Buffer(); | 180 const uint8_t* old_start = old_stream->Buffer(); |
180 size_t old_size = old_stream->Remaining(); | 181 size_t old_size = old_stream->Remaining(); |
181 | 182 |
182 if (old_size != header.slen) | 183 if (old_size != header.slen) |
183 return UNEXPECTED_ERROR; | 184 return UNEXPECTED_ERROR; |
184 | 185 |
185 if (CalculateCrc(old_start, old_size) != header.scrc32) | 186 if (CalculateCrc(old_start, old_size) != header.scrc32) |
186 return CRC_ERROR; | 187 return CRC_ERROR; |
187 | 188 |
188 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); | 189 return MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); |
189 | |
190 return OK; | |
191 } | 190 } |
192 | 191 |
193 BSDiffStatus ApplyBinaryPatch(base::File old_file, | 192 BSDiffStatus ApplyBinaryPatch(base::File old_file, |
194 base::File patch_file, | 193 base::File patch_file, |
195 base::File new_file) { | 194 base::File new_file) { |
196 // Set up the old stream. | 195 // Set up the old stream. |
197 base::MemoryMappedFile old_file_mem; | 196 base::MemoryMappedFile old_file_mem; |
198 if (!old_file_mem.Initialize(std::move(old_file))) { | 197 if (!old_file_mem.Initialize(std::move(old_file))) { |
199 return READ_ERROR; | 198 return READ_ERROR; |
200 } | 199 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 new_file_path, | 240 new_file_path, |
242 base::File::FLAG_CREATE_ALWAYS | | 241 base::File::FLAG_CREATE_ALWAYS | |
243 base::File::FLAG_WRITE | | 242 base::File::FLAG_WRITE | |
244 base::File::FLAG_EXCLUSIVE_WRITE)); | 243 base::File::FLAG_EXCLUSIVE_WRITE)); |
245 if (result != OK) | 244 if (result != OK) |
246 base::DeleteFile(new_file_path, false); | 245 base::DeleteFile(new_file_path, false); |
247 return result; | 246 return result; |
248 } | 247 } |
249 | 248 |
250 } // namespace bsdiff | 249 } // namespace bsdiff |
OLD | NEW |