• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 
19 extern int applypatch(int argc, char** argv);
20 
21 // This program applies binary patches to files in a way that is safe
22 // (the original file is not touched until we have the desired
23 // replacement for it) and idempotent (it's okay to run this program
24 // multiple times).
25 //
26 // - if the sha1 hash of <tgt-file> is <tgt-sha1>, does nothing and exits
27 //   successfully.
28 //
29 // - otherwise, if the sha1 hash of <src-file> is <src-sha1>, applies the
30 //   bsdiff <patch> to <src-file> to produce a new file (the type of patch
31 //   is automatically detected from the file header).  If that new
32 //   file has sha1 hash <tgt-sha1>, moves it to replace <tgt-file>, and
33 //   exits successfully.  Note that if <src-file> and <tgt-file> are
34 //   not the same, <src-file> is NOT deleted on success.  <tgt-file>
35 //   may be the string "-" to mean "the same as src-file".
36 //
37 // - otherwise, or if any error is encountered, exits with non-zero
38 //   status.
39 //
40 // <src-file> (or <file> in check mode) may refer to an MTD partition
41 // to read the source data.  See the comments for the
42 // LoadMTDContents() function above for the format of such a filename.
43 
main(int argc,char ** argv)44 int main(int argc, char** argv) {
45   int result = applypatch(argc, argv);
46   if (result == 2) {
47     fprintf(stderr,
48             "usage: %s <src-file> <tgt-file> <tgt-sha1> <tgt-size> "
49             "[<src-sha1>:<patch> ...]\n"
50             "   or  %s -c <file> [<sha1> ...]\n"
51             "   or  %s -s <bytes>\n"
52             "   or  %s -l\n"
53             "\n"
54             "Filenames may be of the form\n"
55             "  MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...\n"
56             "to specify reading from or writing to an MTD partition.\n\n",
57             argv[0], argv[0], argv[0], argv[0]);
58   }
59   return result;
60 }
61