@gfean/react-native-bundle-drop 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BundleDrop.podspec +9 -2
- package/README.md +19 -0
- package/android/build.gradle +25 -4
- package/android/src/main/cpp/CMakeLists.txt +33 -0
- package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
- package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
- package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
- package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropBundleVerifier.swift +106 -0
- package/ios/BundleDropFileOps.swift +149 -0
- package/ios/BundleDropModule.swift +100 -11
- package/ios/BundleDropOtaResolver.swift +149 -3
- package/ios/BundleDropZipExtractor.m +75 -3
- package/lib/CLI/cli.js +1 -8
- package/lib/CLI/scripts/upload-cli.d.ts +0 -1
- package/lib/CLI/scripts/upload-cli.js +26 -20
- package/lib/api/client.d.ts +11 -1
- package/lib/api/client.js +84 -17
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +65 -13
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/fs/bundlePointer.d.ts +2 -1
- package/lib/fs/bundlePointer.js +34 -6
- package/lib/fs/fsUtils.js +4 -1
- package/lib/injectImageResolver.js +82 -75
- package/lib/install/bundleInstallShared.d.ts +8 -0
- package/lib/install/bundleInstallShared.js +97 -0
- package/lib/install/bundleVerification.d.ts +5 -0
- package/lib/install/bundleVerification.js +34 -0
- package/lib/install/installFromZip.d.ts +2 -5
- package/lib/install/installFromZip.js +33 -68
- package/lib/loadConfig.js +12 -1
- package/lib/manager/downloadAndInstall.d.ts +9 -0
- package/lib/manager/downloadAndInstall.js +84 -24
- package/lib/manager/reporting.js +26 -2
- package/lib/manager/rollbackState.js +21 -12
- package/lib/manager/updateCheck.js +89 -11
- package/lib/manager/updateState.js +3 -9
- package/lib/manifest/bundleManifest.d.ts +33 -0
- package/lib/manifest/bundleManifest.js +298 -0
- package/lib/native/bundleDropNative.js +1 -2
- package/lib/native/fs.d.ts +14 -0
- package/lib/native/fs.js +35 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
- package/lib/patch-engine/installFromPatchSet.js +143 -0
- package/lib/patch-engine/patchOperations.d.ts +33 -0
- package/lib/patch-engine/patchOperations.js +77 -0
- package/lib/patch-engine/patchTransport.d.ts +18 -0
- package/lib/patch-engine/patchTransport.js +81 -0
- package/lib/patchAlgorithms.d.ts +4 -0
- package/lib/patchAlgorithms.js +9 -0
- package/lib/runtime/service.js +43 -9
- package/lib/scripts/bundle.d.ts +3 -0
- package/lib/scripts/bundle.js +184 -41
- package/lib/scripts/download-bundle.js +18 -7
- package/lib/scripts/upload-bundle.js +25 -28
- package/package.json +43 -5
- package/third_party/xdelta/NOTICE +7 -0
- package/third_party/xdelta/PROVENANCE.md +10 -0
- package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
- package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
- package/third_party/xdelta/xdelta3/LICENSE +176 -0
- package/third_party/xdelta/xdelta3/config.h +34 -0
- package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
- package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
- package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
- package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
- package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
- package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
- package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
- package/lib/CLI/scripts/init-native-config.d.ts +0 -18
- package/lib/CLI/scripts/init-native-config.js +0 -539
- package/lib/assetExtensions.d.ts +0 -4
- package/lib/assetExtensions.js +0 -35
|
@@ -51,6 +51,22 @@ const projectRoot_1 = require("./projectRoot");
|
|
|
51
51
|
Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
|
|
52
52
|
const resolve_ios_version_1 = require("./resolve-ios-version");
|
|
53
53
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
|
|
54
|
+
const readManifestRuntimeVersion = (manifestPath) => {
|
|
55
|
+
let manifest;
|
|
56
|
+
try {
|
|
57
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new Error(`bundle-manifest.json is required and must be valid JSON: ${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
if (manifest.manifestVersion !== 1) {
|
|
63
|
+
throw new Error('bundle-manifest.json must use manifestVersion 1');
|
|
64
|
+
}
|
|
65
|
+
if (typeof manifest.runtimeVersion !== 'string' || !manifest.runtimeVersion) {
|
|
66
|
+
throw new Error('bundle-manifest.json is missing runtimeVersion');
|
|
67
|
+
}
|
|
68
|
+
return manifest.runtimeVersion;
|
|
69
|
+
};
|
|
54
70
|
function parseAndroidVersionFromGradle(filePath) {
|
|
55
71
|
if (!fs.existsSync(filePath)) {
|
|
56
72
|
console.error(`❌ build.gradle not found at ${filePath}`);
|
|
@@ -71,6 +87,7 @@ const cleanupArtifacts = (platform, zipPath) => {
|
|
|
71
87
|
const filesToDelete = [
|
|
72
88
|
zipPath,
|
|
73
89
|
path.join(outputDir, `metadata-${suffix}.json`),
|
|
90
|
+
path.join(outputDir, 'bundle-manifest.json'),
|
|
74
91
|
path.join(outputDir, 'main.jsbundle'),
|
|
75
92
|
path.join(outputDir, 'main.jsbundle.map'),
|
|
76
93
|
];
|
|
@@ -143,8 +160,6 @@ async function runUploadBundle(options) {
|
|
|
143
160
|
const buildGradlePath = buildGradleArg?.split('=')[1];
|
|
144
161
|
const channelArg = args.find(arg => arg.startsWith('--channel='));
|
|
145
162
|
const channelName = channelArg?.split('=')[1];
|
|
146
|
-
const runtimeVersionArg = args.find(arg => arg.startsWith('--runtimeVersion='));
|
|
147
|
-
const runtimeVersionOverride = runtimeVersionArg?.split('=')[1];
|
|
148
163
|
const releaseNotesArg = args.find(arg => arg.startsWith('--release-notes='));
|
|
149
164
|
let releaseNotes = releaseNotesArg ? releaseNotesArg.split('=')[1] : undefined;
|
|
150
165
|
const generateSourceMap = args.includes('--sourcemap');
|
|
@@ -220,33 +235,14 @@ async function runUploadBundle(options) {
|
|
|
220
235
|
console.log(`📦 Running bundler for ${platform}...`);
|
|
221
236
|
(0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
|
|
222
237
|
stdio: 'inherit',
|
|
238
|
+
env: {
|
|
239
|
+
...process.env,
|
|
240
|
+
BUNDLE_DROP_APP_VERSION: version,
|
|
241
|
+
},
|
|
223
242
|
});
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const parsed = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
|
|
228
|
-
runtimeVersion = parsed.runtimeVersion;
|
|
229
|
-
if (runtimeVersion) {
|
|
230
|
-
console.log(`🆔 Runtime Version: ${runtimeVersion}`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
// ignore; backend can derive from metadata in zip
|
|
235
|
-
}
|
|
236
|
-
if (runtimeVersionOverride) {
|
|
237
|
-
runtimeVersion = runtimeVersionOverride;
|
|
238
|
-
console.log(`🆔 Runtime Version (override flag): ${runtimeVersion}`);
|
|
239
|
-
}
|
|
240
|
-
else if (!runtimeVersion) {
|
|
241
|
-
runtimeVersion = config.runtimeVersion?.[platform];
|
|
242
|
-
if (runtimeVersion) {
|
|
243
|
-
console.log(`🆔 Runtime Version (from config): ${runtimeVersion}`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (!runtimeVersion) {
|
|
247
|
-
console.error('❌ runtimeVersion could not be determined; aborting upload.');
|
|
248
|
-
process.exit(1);
|
|
249
|
-
}
|
|
243
|
+
const manifestPath = path.join(outputDir, 'bundle-manifest.json');
|
|
244
|
+
runtimeVersion = readManifestRuntimeVersion(manifestPath);
|
|
245
|
+
console.log(`🆔 Runtime Version: ${runtimeVersion}`);
|
|
250
246
|
}
|
|
251
247
|
catch (err) {
|
|
252
248
|
console.error('❌ Failed to bundle:', err);
|
|
@@ -315,6 +311,7 @@ async function runUploadBundle(options) {
|
|
|
315
311
|
(0, exports.cleanupArtifacts)(platform, zipPath);
|
|
316
312
|
}
|
|
317
313
|
}
|
|
314
|
+
/* istanbul ignore next */
|
|
318
315
|
if (require.main === module) {
|
|
319
316
|
runUploadBundle().catch(() => process.exit(1));
|
|
320
317
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfean/react-native-bundle-drop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"nativeVersion": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"nativeVersion": "0.4.1",
|
|
5
5
|
"description": "Over-the-air (OTA) updates for React Native — ship fixes instantly, no App Store or Play Store delays",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -40,11 +40,34 @@
|
|
|
40
40
|
"test": "jest --runInBand",
|
|
41
41
|
"test:coverage": "jest --runInBand --coverage",
|
|
42
42
|
"coverage:check": "node scripts/check-coverage-thresholds.cjs",
|
|
43
|
-
"test:android": "node scripts/run-android-tests.cjs",
|
|
43
|
+
"test:android:unit": "node scripts/run-android-tests.cjs",
|
|
44
|
+
"test:android": "yarn test:android:unit",
|
|
45
|
+
"test:android:device": "node scripts/run-android-instrumented-tests.cjs",
|
|
44
46
|
"test:ios": "node scripts/run-ios-tests.cjs",
|
|
45
|
-
"test:native": "yarn
|
|
47
|
+
"test:native": "yarn verify:native",
|
|
48
|
+
"test:harness": "jest --runInBand src/tests/harness",
|
|
49
|
+
"harness:app:install": "node scripts/harness/install-app-deps.cjs",
|
|
50
|
+
"harness:app:install:rn85:new": "node scripts/harness/install-app-deps.cjs rn-0.85-new-arch",
|
|
51
|
+
"harness:app:install:rn71:old": "node scripts/harness/install-app-deps.cjs rn-0.71-old-arch",
|
|
52
|
+
"harness:app:install:rn74:old": "node scripts/harness/install-app-deps.cjs rn-0.74-old-arch",
|
|
53
|
+
"harness:app:install:rn78:old": "node scripts/harness/install-app-deps.cjs rn-0.78-old-arch",
|
|
54
|
+
"harness:ios": "node scripts/harness/run-app-harness.cjs ios",
|
|
55
|
+
"harness:android": "node scripts/harness/run-app-harness.cjs android",
|
|
56
|
+
"harness:ios:rn85:new": "node scripts/harness/run-app-harness.cjs ios rn-0.85-new-arch",
|
|
57
|
+
"harness:android:rn85:new": "node scripts/harness/run-app-harness.cjs android rn-0.85-new-arch",
|
|
58
|
+
"harness:ios:rn71:old": "node scripts/harness/run-app-harness.cjs ios rn-0.71-old-arch",
|
|
59
|
+
"harness:android:rn71:old": "node scripts/harness/run-app-harness.cjs android rn-0.71-old-arch",
|
|
60
|
+
"harness:ios:rn74:old": "node scripts/harness/run-app-harness.cjs ios rn-0.74-old-arch",
|
|
61
|
+
"harness:android:rn74:old": "node scripts/harness/run-app-harness.cjs android rn-0.74-old-arch",
|
|
62
|
+
"harness:ios:rn78:old": "node scripts/harness/run-app-harness.cjs ios rn-0.78-old-arch",
|
|
63
|
+
"harness:android:rn78:old": "node scripts/harness/run-app-harness.cjs android rn-0.78-old-arch",
|
|
64
|
+
"harness:backend:live": "node scripts/harness/live-backend-smoke.cjs",
|
|
65
|
+
"harness:pack": "node scripts/harness/pack-dry-run.cjs",
|
|
46
66
|
"coverage:gate": "yarn test:coverage && yarn coverage:check",
|
|
47
|
-
"
|
|
67
|
+
"verify:quick": "yarn coverage:gate && yarn harness:pack",
|
|
68
|
+
"verify:native": "yarn test:android && yarn test:ios",
|
|
69
|
+
"verify:release": "yarn verify:quick && yarn verify:native",
|
|
70
|
+
"prepublishOnly": "yarn clean && yarn build && yarn harness:pack",
|
|
48
71
|
"build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
|
|
49
72
|
"publish:local": "yalc publish --private"
|
|
50
73
|
},
|
|
@@ -78,6 +101,21 @@
|
|
|
78
101
|
"android/build.gradle",
|
|
79
102
|
"android/gradle.properties",
|
|
80
103
|
"ios/*.{m,h,mm,swift}",
|
|
104
|
+
"third_party/xdelta/NOTICE",
|
|
105
|
+
"third_party/xdelta/PROVENANCE.md",
|
|
106
|
+
"third_party/xdelta/bundle_drop_xdelta.c",
|
|
107
|
+
"third_party/xdelta/bundle_drop_xdelta.h",
|
|
108
|
+
"third_party/xdelta/xdelta3/LICENSE",
|
|
109
|
+
"third_party/xdelta/xdelta3/config.h",
|
|
110
|
+
"third_party/xdelta/xdelta3/xdelta3-cfgs.h",
|
|
111
|
+
"third_party/xdelta/xdelta3/xdelta3-decode.h",
|
|
112
|
+
"third_party/xdelta/xdelta3/xdelta3-hash.h",
|
|
113
|
+
"third_party/xdelta/xdelta3/xdelta3-internal.h",
|
|
114
|
+
"third_party/xdelta/xdelta3/xdelta3-list.h",
|
|
115
|
+
"third_party/xdelta/xdelta3/xdelta3.c",
|
|
116
|
+
"third_party/xdelta/xdelta3/xdelta3.h",
|
|
117
|
+
"!third_party/xdelta/README.md",
|
|
118
|
+
"!third_party/xdelta/xdelta3/README.md",
|
|
81
119
|
"BundleDrop.podspec",
|
|
82
120
|
"react-native.config.js",
|
|
83
121
|
"README.md"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Xdelta Provenance
|
|
2
|
+
|
|
3
|
+
- Upstream: https://github.com/jmacd/xdelta
|
|
4
|
+
- Branch: release3_1_apl
|
|
5
|
+
- Commit: 7508fd2a823443b1f0173ca361620f21d62a7d37
|
|
6
|
+
- License: Apache License 2.0
|
|
7
|
+
- Imported: 2026-05-21
|
|
8
|
+
|
|
9
|
+
This SDK vendors the Apache-licensed xdelta source for native mobile
|
|
10
|
+
VCDIFF decode/apply only. Do not replace it with `jmacd/xdelta-gpl`.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#include "bundle_drop_xdelta.h"
|
|
2
|
+
|
|
3
|
+
#include <errno.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
|
|
9
|
+
#include "xdelta3/xdelta3.h"
|
|
10
|
+
|
|
11
|
+
#define BD_XDELTA_INPUT_BUFFER_SIZE (64U * 1024U)
|
|
12
|
+
#define BD_XDELTA_SOURCE_BLOCK_SIZE (64U * 1024U)
|
|
13
|
+
#define BD_XDELTA_MAX_OUTPUT_BYTES (512ULL * 1024ULL * 1024ULL)
|
|
14
|
+
|
|
15
|
+
typedef struct {
|
|
16
|
+
FILE *source_file;
|
|
17
|
+
uint8_t source_buffer[BD_XDELTA_SOURCE_BLOCK_SIZE];
|
|
18
|
+
} bd_xdelta_source_context;
|
|
19
|
+
|
|
20
|
+
static void bd_xdelta_set_error(char *buffer, size_t len, const char *message) {
|
|
21
|
+
if (buffer == NULL || len == 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (message == NULL) {
|
|
25
|
+
message = "xdelta error";
|
|
26
|
+
}
|
|
27
|
+
snprintf(buffer, len, "%s", message);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static const char *bd_xdelta_error_message(xd3_stream *stream, int ret) {
|
|
31
|
+
if (stream != NULL && stream->msg != NULL) {
|
|
32
|
+
return stream->msg;
|
|
33
|
+
}
|
|
34
|
+
const char *message = xd3_strerror(ret);
|
|
35
|
+
return message != NULL ? message : "xdelta decode failed";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static int bd_xdelta_source_size(const char *path, xoff_t *size_out) {
|
|
39
|
+
struct stat st;
|
|
40
|
+
if (stat(path, &st) != 0) {
|
|
41
|
+
return errno != 0 ? errno : EIO;
|
|
42
|
+
}
|
|
43
|
+
if (st.st_size < 0) {
|
|
44
|
+
return EINVAL;
|
|
45
|
+
}
|
|
46
|
+
*size_out = (xoff_t)st.st_size;
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static int bd_xdelta_getblk(xd3_stream *stream, xd3_source *source, xoff_t blkno) {
|
|
51
|
+
(void)stream;
|
|
52
|
+
bd_xdelta_source_context *context = (bd_xdelta_source_context *)source->ioh;
|
|
53
|
+
if (context == NULL || context->source_file == NULL) {
|
|
54
|
+
return EINVAL;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
xoff_t offset = blkno * (xoff_t)source->blksize;
|
|
58
|
+
if (fseeko(context->source_file, (off_t)offset, SEEK_SET) != 0) {
|
|
59
|
+
return errno != 0 ? errno : EIO;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
size_t bytes_read = fread(context->source_buffer, 1, source->blksize, context->source_file);
|
|
63
|
+
if (ferror(context->source_file)) {
|
|
64
|
+
return errno != 0 ? errno : EIO;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
source->curblkno = blkno;
|
|
68
|
+
source->onblk = (usize_t)bytes_read;
|
|
69
|
+
source->curblk = context->source_buffer;
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
int bd_xdelta_apply(
|
|
74
|
+
const char *base_path,
|
|
75
|
+
const char *patch_path,
|
|
76
|
+
const char *output_path,
|
|
77
|
+
char *error_buffer,
|
|
78
|
+
size_t error_buffer_len
|
|
79
|
+
) {
|
|
80
|
+
if (base_path == NULL || patch_path == NULL || output_path == NULL) {
|
|
81
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "xdelta paths must not be null");
|
|
82
|
+
return -1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
FILE *base_file = NULL;
|
|
86
|
+
FILE *patch_file = NULL;
|
|
87
|
+
FILE *output_file = NULL;
|
|
88
|
+
xd3_stream stream;
|
|
89
|
+
xd3_config config;
|
|
90
|
+
xd3_source source;
|
|
91
|
+
bd_xdelta_source_context source_context;
|
|
92
|
+
uint8_t input_buffer[BD_XDELTA_INPUT_BUFFER_SIZE];
|
|
93
|
+
uint64_t total_output = 0;
|
|
94
|
+
xoff_t source_size = 0;
|
|
95
|
+
int result = -1;
|
|
96
|
+
|
|
97
|
+
memset(&stream, 0, sizeof(stream));
|
|
98
|
+
memset(&config, 0, sizeof(config));
|
|
99
|
+
memset(&source, 0, sizeof(source));
|
|
100
|
+
memset(&source_context, 0, sizeof(source_context));
|
|
101
|
+
|
|
102
|
+
int stat_error = bd_xdelta_source_size(base_path, &source_size);
|
|
103
|
+
if (stat_error != 0) {
|
|
104
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to stat xdelta base file");
|
|
105
|
+
goto cleanup;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
base_file = fopen(base_path, "rb");
|
|
109
|
+
if (base_file == NULL) {
|
|
110
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to open xdelta base file");
|
|
111
|
+
goto cleanup;
|
|
112
|
+
}
|
|
113
|
+
patch_file = fopen(patch_path, "rb");
|
|
114
|
+
if (patch_file == NULL) {
|
|
115
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to open xdelta patch file");
|
|
116
|
+
goto cleanup;
|
|
117
|
+
}
|
|
118
|
+
output_file = fopen(output_path, "wb");
|
|
119
|
+
if (output_file == NULL) {
|
|
120
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to open xdelta output file");
|
|
121
|
+
goto cleanup;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
source_context.source_file = base_file;
|
|
125
|
+
source.blksize = BD_XDELTA_SOURCE_BLOCK_SIZE;
|
|
126
|
+
source.name = base_path;
|
|
127
|
+
source.ioh = &source_context;
|
|
128
|
+
source.max_winsize = XD3_DEFAULT_SRCWINSZ;
|
|
129
|
+
|
|
130
|
+
xd3_init_config(&config, XD3_ADLER32_NOVER);
|
|
131
|
+
config.winsize = XD3_DEFAULT_WINSIZE;
|
|
132
|
+
config.getblk = bd_xdelta_getblk;
|
|
133
|
+
|
|
134
|
+
int ret = xd3_config_stream(&stream, &config);
|
|
135
|
+
if (ret != 0) {
|
|
136
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, bd_xdelta_error_message(&stream, ret));
|
|
137
|
+
goto cleanup;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ret = xd3_set_source_and_size(&stream, &source, source_size);
|
|
141
|
+
if (ret != 0) {
|
|
142
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, bd_xdelta_error_message(&stream, ret));
|
|
143
|
+
goto cleanup;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
size_t bytes_read;
|
|
147
|
+
do {
|
|
148
|
+
bytes_read = fread(input_buffer, 1, sizeof(input_buffer), patch_file);
|
|
149
|
+
if (ferror(patch_file)) {
|
|
150
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to read xdelta patch file");
|
|
151
|
+
goto cleanup;
|
|
152
|
+
}
|
|
153
|
+
if (bytes_read < sizeof(input_buffer)) {
|
|
154
|
+
stream.flags |= XD3_FLUSH;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
xd3_avail_input(&stream, input_buffer, (usize_t)bytes_read);
|
|
158
|
+
|
|
159
|
+
for (;;) {
|
|
160
|
+
ret = xd3_decode_input(&stream);
|
|
161
|
+
if (ret == XD3_INPUT) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (ret == XD3_GOTHEADER || ret == XD3_WINSTART || ret == XD3_WINFINISH) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (ret == XD3_OUTPUT) {
|
|
168
|
+
if (total_output + stream.avail_out > BD_XDELTA_MAX_OUTPUT_BYTES) {
|
|
169
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "xdelta output exceeds safety limit");
|
|
170
|
+
goto cleanup;
|
|
171
|
+
}
|
|
172
|
+
if (fwrite(stream.next_out, 1, stream.avail_out, output_file) != stream.avail_out) {
|
|
173
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to write xdelta output file");
|
|
174
|
+
goto cleanup;
|
|
175
|
+
}
|
|
176
|
+
total_output += stream.avail_out;
|
|
177
|
+
xd3_consume_output(&stream);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, bd_xdelta_error_message(&stream, ret));
|
|
182
|
+
goto cleanup;
|
|
183
|
+
}
|
|
184
|
+
} while (bytes_read == sizeof(input_buffer));
|
|
185
|
+
|
|
186
|
+
ret = xd3_close_stream(&stream);
|
|
187
|
+
if (ret != 0) {
|
|
188
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, bd_xdelta_error_message(&stream, ret));
|
|
189
|
+
goto cleanup;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (fflush(output_file) != 0) {
|
|
193
|
+
bd_xdelta_set_error(error_buffer, error_buffer_len, "failed to flush xdelta output file");
|
|
194
|
+
goto cleanup;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
result = 0;
|
|
198
|
+
|
|
199
|
+
cleanup:
|
|
200
|
+
if (result != 0) {
|
|
201
|
+
xd3_abort_stream(&stream);
|
|
202
|
+
}
|
|
203
|
+
xd3_free_stream(&stream);
|
|
204
|
+
if (output_file != NULL) {
|
|
205
|
+
fclose(output_file);
|
|
206
|
+
}
|
|
207
|
+
if (patch_file != NULL) {
|
|
208
|
+
fclose(patch_file);
|
|
209
|
+
}
|
|
210
|
+
if (base_file != NULL) {
|
|
211
|
+
fclose(base_file);
|
|
212
|
+
}
|
|
213
|
+
if (result != 0) {
|
|
214
|
+
remove(output_path);
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
int bd_xdelta_self_test(void) {
|
|
220
|
+
static const uint8_t base[] = "Bundle Drop xdelta base fixture\nline one\n";
|
|
221
|
+
static const uint8_t expected[] = "Bundle Drop xdelta target fixture\nline two\n";
|
|
222
|
+
static const uint8_t patch[] = {
|
|
223
|
+
0xd6, 0xc3, 0xc4, 0x00, 0x04, 0x15, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74,
|
|
224
|
+
0x2e, 0x74, 0x78, 0x74, 0x2f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x74,
|
|
225
|
+
0x78, 0x74, 0x2f, 0x05, 0x25, 0x00, 0x1a, 0x2b, 0x00, 0x0a, 0x05, 0x02,
|
|
226
|
+
0x5d, 0x5e, 0x0f, 0xb6, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x74, 0x77,
|
|
227
|
+
0x6f, 0x0a, 0x13, 0x13, 0x07, 0x1e, 0x05, 0x00, 0x17
|
|
228
|
+
};
|
|
229
|
+
uint8_t output[sizeof(expected)];
|
|
230
|
+
usize_t output_size = sizeof(output);
|
|
231
|
+
int ret = xd3_decode_memory(
|
|
232
|
+
patch,
|
|
233
|
+
(usize_t)sizeof(patch),
|
|
234
|
+
base,
|
|
235
|
+
(usize_t)(sizeof(base) - 1),
|
|
236
|
+
output,
|
|
237
|
+
&output_size,
|
|
238
|
+
(usize_t)sizeof(output),
|
|
239
|
+
XD3_ADLER32_NOVER
|
|
240
|
+
);
|
|
241
|
+
if (ret != 0) {
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
if (output_size != sizeof(expected) - 1) {
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
return memcmp(output, expected, sizeof(expected) - 1) == 0 ? 1 : 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const char *bd_xdelta_version(void) {
|
|
251
|
+
return "xdelta 3.1.1-apl release3_1_apl 7508fd2a823443b1f0173ca361620f21d62a7d37";
|
|
252
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef BUNDLE_DROP_XDELTA_H
|
|
2
|
+
#define BUNDLE_DROP_XDELTA_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
int bd_xdelta_apply(
|
|
11
|
+
const char *base_path,
|
|
12
|
+
const char *patch_path,
|
|
13
|
+
const char *output_path,
|
|
14
|
+
char *error_buffer,
|
|
15
|
+
size_t error_buffer_len
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
int bd_xdelta_self_test(void);
|
|
19
|
+
|
|
20
|
+
const char *bd_xdelta_version(void);
|
|
21
|
+
|
|
22
|
+
#ifdef __cplusplus
|
|
23
|
+
}
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#endif
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#ifndef BUNDLE_DROP_XDELTA_CONFIG_H
|
|
2
|
+
#define BUNDLE_DROP_XDELTA_CONFIG_H
|
|
3
|
+
|
|
4
|
+
#if !defined(__cplusplus) && !defined(static_assert)
|
|
5
|
+
#define static_assert _Static_assert
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#define SIZEOF_UNSIGNED_INT 4
|
|
9
|
+
#define SIZEOF_UNSIGNED_LONG_LONG 8
|
|
10
|
+
|
|
11
|
+
#if defined(__LP64__) || defined(_WIN64)
|
|
12
|
+
#define SIZEOF_SIZE_T 8
|
|
13
|
+
#define SIZEOF_UNSIGNED_LONG 8
|
|
14
|
+
#else
|
|
15
|
+
#define SIZEOF_SIZE_T 4
|
|
16
|
+
#define SIZEOF_UNSIGNED_LONG 4
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#define XD3_MAIN 0
|
|
20
|
+
#define XD3_ENCODER 0
|
|
21
|
+
#define REGRESSION_TEST 0
|
|
22
|
+
#define NOT_MAIN 0
|
|
23
|
+
#define PYTHON_MODULE 0
|
|
24
|
+
#define SWIG_MODULE 0
|
|
25
|
+
#define SECONDARY_DJW 0
|
|
26
|
+
#define SECONDARY_FGK 0
|
|
27
|
+
#define SECONDARY_LZMA 0
|
|
28
|
+
|
|
29
|
+
#define XD3_HARDMAXWINSIZE (1U << 26)
|
|
30
|
+
#define XD3_DEFAULT_WINSIZE (1U << 20)
|
|
31
|
+
#define XD3_DEFAULT_SRCWINSZ (1U << 26)
|
|
32
|
+
#define XD3_DEFAULT_IOPT_SIZE (1U << 15)
|
|
33
|
+
|
|
34
|
+
#endif
|