OLD | NEW |
1 /*- | 1 /*- |
2 * Copyright 2003,2004 Colin Percival | 2 * Copyright 2003,2004 Colin Percival |
3 * All rights reserved | 3 * All rights reserved |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted providing that the following conditions | 6 * modification, are permitted providing that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 * POSSIBILITY OF SUCH DAMAGE. | 24 * POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 * Changelog: | 26 * Changelog: |
27 * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to | 27 * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to |
28 * the header, and make all the types 32-bit. | 28 * the header, and make all the types 32-bit. |
29 * --Benjamin Smedberg <benjamin@smedbergs.us> | 29 * --Benjamin Smedberg <benjamin@smedbergs.us> |
30 * 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} | 30 * 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} |
31 * Changed status to an enum, removed unused status codes. | 31 * Changed status to an enum, removed unused status codes. |
32 * --Stephen Adams <sra@chromium.org> | 32 * --Stephen Adams <sra@chromium.org> |
| 33 * 2013-04-10 - Added wrapper to apply a patch directly to files. |
| 34 * --Joshua Pawlicki <waffles@chromium.org> |
33 */ | 35 */ |
34 | 36 |
35 #ifndef COURGETTE_BSDIFF_H_ | 37 #ifndef COURGETTE_BSDIFF_H_ |
36 #define COURGETTE_BSDIFF_H_ | 38 #define COURGETTE_BSDIFF_H_ |
37 | 39 |
38 #include "base/basictypes.h" | 40 #include "base/basictypes.h" |
| 41 #include "base/file_util.h" |
39 | 42 |
40 namespace courgette { | 43 namespace courgette { |
41 | 44 |
42 enum BSDiffStatus { | 45 enum BSDiffStatus { |
43 OK = 0, | 46 OK = 0, |
44 MEM_ERROR = 1, | 47 MEM_ERROR = 1, |
45 CRC_ERROR = 2, | 48 CRC_ERROR = 2, |
46 READ_ERROR = 3, | 49 READ_ERROR = 3, |
47 UNEXPECTED_ERROR = 4 | 50 UNEXPECTED_ERROR = 4, |
| 51 WRITE_ERROR = 5 |
48 }; | 52 }; |
49 | 53 |
50 class SourceStream; | 54 class SourceStream; |
51 class SinkStream; | 55 class SinkStream; |
52 | 56 |
53 // Creates a binary patch. | 57 // Creates a binary patch. |
54 // | 58 // |
55 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, | 59 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, |
56 SourceStream* new_stream, | 60 SourceStream* new_stream, |
57 SinkStream* patch_stream); | 61 SinkStream* patch_stream); |
58 | 62 |
59 // Applies the given patch file to a given source file. This method validates | 63 // Applies the given patch file to a given source file. This method validates |
60 // the CRC of the original file stored in the patch file, before applying the | 64 // the CRC of the original file stored in the patch file, before applying the |
61 // patch to it. | 65 // patch to it. |
62 // | 66 // |
63 BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream, | 67 BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream, |
64 SourceStream* patch_stream, | 68 SourceStream* patch_stream, |
65 SinkStream* new_stream); | 69 SinkStream* new_stream); |
66 | 70 |
| 71 // As above, but simply takes the file paths. |
| 72 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_stream, |
| 73 const base::FilePath& patch_stream, |
| 74 const base::FilePath& new_stream); |
67 | 75 |
68 // The following declarations are common to the patch-creation and | 76 // The following declarations are common to the patch-creation and |
69 // patch-application code. | 77 // patch-application code. |
70 | 78 |
71 // The patch stream starts with a MBSPatchHeader. | 79 // The patch stream starts with a MBSPatchHeader. |
72 typedef struct MBSPatchHeader_ { | 80 typedef struct MBSPatchHeader_ { |
73 char tag[8]; // Contains MBS_PATCH_HEADER_TAG | 81 char tag[8]; // Contains MBS_PATCH_HEADER_TAG |
74 uint32 slen; // Length of the file to be patched. | 82 uint32 slen; // Length of the file to be patched. |
75 uint32 scrc32; // CRC32 of the file to be patched. | 83 uint32 scrc32; // CRC32 of the file to be patched. |
76 uint32 dlen; // Length of the result file. | 84 uint32 dlen; // Length of the result file. |
77 } MBSPatchHeader; | 85 } MBSPatchHeader; |
78 | 86 |
79 // This is the value for the tag field. Must match length exactly, not counting | 87 // This is the value for the tag field. Must match length exactly, not counting |
80 // null at end of string. | 88 // null at end of string. |
81 #define MBS_PATCH_HEADER_TAG "GBSDIF42" | 89 #define MBS_PATCH_HEADER_TAG "GBSDIF42" |
82 | 90 |
83 } // namespace | 91 } // namespace |
84 #endif // COURGETTE_BSDIFF_H_ | 92 #endif // COURGETTE_BSDIFF_H_ |
OLD | NEW |