auto import from //branches/cupcake/...@127101
This commit is contained in:
@@ -17,12 +17,12 @@ include $(CLEAR_VARS)
|
||||
|
||||
ifneq ($(TARGET_SIMULATOR),true)
|
||||
|
||||
LOCAL_SRC_FILES := applypatch.c xdelta3.c bsdiff.c freecache.c
|
||||
LOCAL_SRC_FILES := applypatch.c bsdiff.c freecache.c
|
||||
LOCAL_MODULE := applypatch
|
||||
LOCAL_FORCE_STATIC_EXECUTABLE := true
|
||||
LOCAL_MODULE_TAGS := eng
|
||||
LOCAL_C_INCLUDES += external/xdelta3 external/bzip2
|
||||
LOCAL_STATIC_LIBRARIES += libxdelta3 libmincrypt libbz libc
|
||||
LOCAL_C_INCLUDES += external/bzip2
|
||||
LOCAL_STATIC_LIBRARIES += libmincrypt libbz libc
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
|
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -209,24 +206,6 @@ int CheckMode(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int ShowLicenses() {
|
||||
puts("\nCopyright (C) 2008 The Android Open Source Project\n"
|
||||
"\n"
|
||||
"This program is free software; you can redistribute it and/or\n"
|
||||
"modify it under the terms of the GNU General Public License\n"
|
||||
"as published by the Free Software Foundation; either version 2\n"
|
||||
"of the License, or (at your option) any later version.\n"
|
||||
"\n"
|
||||
"This program is distributed in the hope that it will be useful,\n"
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
"GNU General Public License for more details.\n"
|
||||
"\n"
|
||||
"You should have received a copy of the GNU General Public License\n"
|
||||
"along with this program; if not, write to the Free Software\n"
|
||||
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n"
|
||||
"02110-1301, USA.\n"
|
||||
"\n------------------\n"
|
||||
);
|
||||
ShowBSDiffLicense();
|
||||
return 0;
|
||||
}
|
||||
@@ -251,10 +230,10 @@ size_t FreeSpaceForFile(const char* filename) {
|
||||
// successfully.
|
||||
//
|
||||
// - otherwise, if the sha1 hash of <file> is <src-sha1>, applies the
|
||||
// xdelta3 or bsdiff <patch> to <file> to produce a new file (the
|
||||
// type of patch is automatically detected from the file header).
|
||||
// If that new file has sha1 hash <tgt-sha1>, moves it to replace
|
||||
// <file>, and exits successfully.
|
||||
// bsdiff <patch> to <file> to produce a new file (the type of patch
|
||||
// is automatically detected from the file header). If that new
|
||||
// file has sha1 hash <tgt-sha1>, moves it to replace <file>, and
|
||||
// exits successfully.
|
||||
//
|
||||
// - otherwise, or if any error is encountered, exits with non-zero
|
||||
// status.
|
||||
@@ -426,12 +405,8 @@ int main(int argc, char** argv) {
|
||||
header[2] == 0xc4 && header[3] == 0) {
|
||||
// xdelta3 patches begin "VCD" (with the high bits set) followed
|
||||
// by a zero byte (the version number).
|
||||
int result = ApplyXDelta3Patch(source_to_use->data, source_to_use->size,
|
||||
patch_filename, output, &ctx);
|
||||
if (result != 0) {
|
||||
fprintf(stderr, "ApplyXDelta3Patch failed\n");
|
||||
return result;
|
||||
}
|
||||
fprintf(stderr, "error: xdelta3 patches no longer supported\n");
|
||||
return 1;
|
||||
} else if (header_bytes_read >= 8 &&
|
||||
memcmp(header, "BSDIFF40", 8) == 0) {
|
||||
int result = ApplyBSDiffPatch(source_to_use->data, source_to_use->size,
|
||||
|
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _APPLYPATCH_H
|
||||
@@ -44,11 +41,6 @@ typedef struct _FileContents {
|
||||
// applypatch.c
|
||||
size_t FreeSpaceForFile(const char* filename);
|
||||
|
||||
// xdelta3.c
|
||||
int ApplyXDelta3Patch(const unsigned char* old_data, ssize_t old_size,
|
||||
const char* patch_filename,
|
||||
FILE* output, SHA_CTX* ctx);
|
||||
|
||||
// bsdiff.c
|
||||
void ShowBSDiffLicense();
|
||||
int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
|
||||
|
@@ -128,7 +128,7 @@ run_command $WORK_DIR/applypatch -c $WORK_DIR/old.file $BAD2_SHA1 $BAD1_SHA1 &&
|
||||
# --------------- apply patch ----------------------
|
||||
|
||||
$ADB push $DATA_DIR/old.file $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
|
||||
|
||||
# Check that the partition has enough space to apply the patch without
|
||||
# copying. If it doesn't, we'll be testing the low-space condition
|
||||
@@ -145,19 +145,6 @@ if (( free_kb * 1024 < NEW_SIZE * 3 / 2 )); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
testname "apply xdelta3 patch"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
|
||||
testname "reapply xdelta3 patch"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
|
||||
$ADB push $DATA_DIR/old.file $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
|
||||
|
||||
testname "apply bsdiff patch"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
@@ -172,7 +159,6 @@ diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
# --------------- apply patch with low space on /system ----------------------
|
||||
|
||||
$ADB push $DATA_DIR/old.file $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
|
||||
|
||||
free_kb=$(free_space $WORK_FS)
|
||||
@@ -182,18 +168,6 @@ run_command dd if=/dev/zero of=$WORK_DIR/bloat.dat count=$((free_kb-512)) bs=102
|
||||
free_kb=$(free_space $WORK_FS)
|
||||
echo "${free_kb}kb free on /$WORK_FS now."
|
||||
|
||||
testname "apply xdelta3 patch with low space"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
|
||||
testname "reapply xdelta3 patch with low space"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
|
||||
$ADB push $DATA_DIR/old.file $WORK_DIR
|
||||
|
||||
testname "apply bsdiff patch with low space"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
@@ -207,7 +181,6 @@ diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
# --------------- apply patch with low space on /system and /cache ----------------------
|
||||
|
||||
$ADB push $DATA_DIR/old.file $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
|
||||
$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
|
||||
|
||||
free_kb=$(free_space $WORK_FS)
|
||||
@@ -216,7 +189,7 @@ echo "${free_kb}kb free on /$WORK_FS"
|
||||
run_command mkdir /cache/subdir
|
||||
run_command 'echo > /cache/subdir/a.file'
|
||||
run_command 'echo > /cache/a.file'
|
||||
run_command mkdir -p /cache/recovery/otatest
|
||||
run_command mkdir /cache/recovery /cache/recovery/otatest
|
||||
run_command 'echo > /cache/recovery/otatest/b.file'
|
||||
run_command "echo > $CACHE_TEMP_SOURCE"
|
||||
free_kb=$(free_space cache)
|
||||
@@ -268,8 +241,8 @@ $ADB push $DATA_DIR/old.file $CACHE_TEMP_SOURCE
|
||||
# put some junk in the old file
|
||||
run_command dd if=/dev/urandom of=$WORK_DIR/old.file count=100 bs=1024 || fail
|
||||
|
||||
testname "apply xdelta3 patch from cache (corrupted source) with low space"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
|
||||
testname "apply bsdiff patch from cache (corrupted source) with low space"
|
||||
run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
|
||||
$ADB pull $WORK_DIR/old.file $tmpdir/patched
|
||||
diff -q $DATA_DIR/new.file $tmpdir/patched || fail
|
||||
|
||||
|
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// This file is a nearly line-for-line copy of bspatch.c from the
|
||||
|
BIN
tools/applypatch/testdata/patch.xdelta3
vendored
BIN
tools/applypatch/testdata/patch.xdelta3
vendored
Binary file not shown.
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "xdelta3.h"
|
||||
#include "mincrypt/sha.h"
|
||||
|
||||
int ApplyXDelta3Patch(const unsigned char* old_data, ssize_t old_size,
|
||||
const char* patch_filename,
|
||||
FILE* output, SHA_CTX* ctx) {
|
||||
#define WINDOW_SIZE 32768
|
||||
|
||||
int ret;
|
||||
xd3_stream stream;
|
||||
xd3_config config;
|
||||
|
||||
xd3_init_config(&config, 0);
|
||||
config.winsize = WINDOW_SIZE;
|
||||
ret = xd3_config_stream(&stream, &config);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "xd3_config_stream error: %s\n", xd3_strerror(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// In xdelta3 terms, the "input" is the patch file: it contains a
|
||||
// sequence of instruction codes and data that will be executed to
|
||||
// produce the output file. The "source" is the original data file;
|
||||
// it is a blob of data to which instructions in the input may refer
|
||||
// (eg, an instruction may say "copy such-and-such range of bytes
|
||||
// from the source to the output").
|
||||
|
||||
// For simplicity, we provide the entire source to xdelta as a
|
||||
// single block. This means it should never have to ask us to load
|
||||
// blocks of the source file.
|
||||
xd3_source source;
|
||||
source.name = "old name";
|
||||
source.size = old_size;
|
||||
source.ioh = NULL;
|
||||
source.blksize = old_size;
|
||||
source.curblkno = 0;
|
||||
source.curblk = old_data;
|
||||
source.onblk = old_size;
|
||||
|
||||
ret = xd3_set_source(&stream, &source);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "xd3_set_source error: %s\n", xd3_strerror(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char buffer[WINDOW_SIZE];
|
||||
FILE* input = fopen(patch_filename, "rb");
|
||||
if (input == NULL) {
|
||||
fprintf(stderr, "failed to open patch file %s: %d (%s)\n",
|
||||
patch_filename, errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t bytes_read;
|
||||
|
||||
do {
|
||||
bytes_read = fread(buffer, 1, WINDOW_SIZE, input);
|
||||
if (feof(input)) {
|
||||
xd3_set_flags(&stream, XD3_FLUSH);
|
||||
}
|
||||
xd3_avail_input(&stream, buffer, bytes_read);
|
||||
process:
|
||||
ret = xd3_decode_input(&stream);
|
||||
switch (ret) {
|
||||
case XD3_INPUT:
|
||||
continue;
|
||||
case XD3_OUTPUT:
|
||||
SHA_update(ctx, stream.next_out, stream.avail_out);
|
||||
if (fwrite(stream.next_out, 1, stream.avail_out, output) !=
|
||||
stream.avail_out) {
|
||||
fprintf(stderr, "short write of output file: %d (%s)\n",
|
||||
errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
xd3_consume_output(&stream);
|
||||
goto process;
|
||||
case XD3_GETSRCBLK:
|
||||
// We provided the entire source file already; it should never
|
||||
// have to ask us for a block.
|
||||
fprintf(stderr, "xd3_decode_input: unexpected GETSRCBLK\n");
|
||||
return 1;
|
||||
case XD3_GOTHEADER:
|
||||
case XD3_WINSTART:
|
||||
case XD3_WINFINISH:
|
||||
// These are informational events we don't care about.
|
||||
goto process;
|
||||
default:
|
||||
fprintf(stderr, "xd3_decode_input: unknown error %s (%s)\n",
|
||||
xd3_strerror(ret), stream.msg);
|
||||
return 1;
|
||||
}
|
||||
} while (!feof(input));
|
||||
|
||||
fclose(input);
|
||||
return 0;
|
||||
|
||||
#undef WINDOW_SIZE
|
||||
}
|
Reference in New Issue
Block a user