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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 89 |
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; |
huangs
2017/03/25 03:07:23
Need to add:
extra_bytes->Skip(extra_bytes->Remai
| |
100 | 100 |
101 const uint8_t* old_position = old_start; | 101 const uint8_t* old_position = old_start; |
102 | 102 |
103 if (header->dlen && !new_stream->Reserve(header->dlen)) | 103 if (header->dlen && !new_stream->Reserve(header->dlen)) |
104 return MEM_ERROR; | 104 return MEM_ERROR; |
105 | 105 |
106 uint32_t pending_diff_zeros = 0; | 106 uint32_t pending_diff_zeros = 0; |
107 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) | 107 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) |
108 return UNEXPECTED_ERROR; | 108 return UNEXPECTED_ERROR; |
109 | 109 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 178 |
179 const uint8_t* old_start = old_stream->Buffer(); | 179 const uint8_t* old_start = old_stream->Buffer(); |
180 size_t old_size = old_stream->Remaining(); | 180 size_t old_size = old_stream->Remaining(); |
181 | 181 |
182 if (old_size != header.slen) | 182 if (old_size != header.slen) |
183 return UNEXPECTED_ERROR; | 183 return UNEXPECTED_ERROR; |
184 | 184 |
185 if (CalculateCrc(old_start, old_size) != header.scrc32) | 185 if (CalculateCrc(old_start, old_size) != header.scrc32) |
186 return CRC_ERROR; | 186 return CRC_ERROR; |
187 | 187 |
188 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); | 188 return MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); |
189 | |
190 return OK; | |
191 } | 189 } |
192 | 190 |
193 BSDiffStatus ApplyBinaryPatch(base::File old_file, | 191 BSDiffStatus ApplyBinaryPatch(base::File old_file, |
194 base::File patch_file, | 192 base::File patch_file, |
195 base::File new_file) { | 193 base::File new_file) { |
196 // Set up the old stream. | 194 // Set up the old stream. |
197 base::MemoryMappedFile old_file_mem; | 195 base::MemoryMappedFile old_file_mem; |
198 if (!old_file_mem.Initialize(std::move(old_file))) { | 196 if (!old_file_mem.Initialize(std::move(old_file))) { |
199 return READ_ERROR; | 197 return READ_ERROR; |
200 } | 198 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 new_file_path, | 239 new_file_path, |
242 base::File::FLAG_CREATE_ALWAYS | | 240 base::File::FLAG_CREATE_ALWAYS | |
243 base::File::FLAG_WRITE | | 241 base::File::FLAG_WRITE | |
244 base::File::FLAG_EXCLUSIVE_WRITE)); | 242 base::File::FLAG_EXCLUSIVE_WRITE)); |
245 if (result != OK) | 243 if (result != OK) |
246 base::DeleteFile(new_file_path, false); | 244 base::DeleteFile(new_file_path, false); |
247 return result; | 245 return result; |
248 } | 246 } |
249 | 247 |
250 } // namespace bsdiff | 248 } // namespace bsdiff |
OLD | NEW |