@gfean/react-native-bundle-drop 0.1.91 → 0.1.94
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.
|
@@ -37,6 +37,14 @@ import Foundation
|
|
|
37
37
|
return nil
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
let lastVersion = UserDefaults.standard.string(forKey: binaryVersionKey)
|
|
41
|
+
if let lastVersion = lastVersion, lastVersion != currentVersion {
|
|
42
|
+
print("BundleDrop: Binary updated (\(lastVersion) → \(currentVersion)), clearing OTA bundle")
|
|
43
|
+
clearOtaState(root: root)
|
|
44
|
+
UserDefaults.standard.set(currentVersion, forKey: binaryVersionKey)
|
|
45
|
+
return nil
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
do {
|
|
41
49
|
let data = try Data(contentsOf: current)
|
|
42
50
|
let obj = try JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
@@ -44,14 +52,6 @@ import Foundation
|
|
|
44
52
|
let url = URL(fileURLWithPath: bundlePath)
|
|
45
53
|
guard fm.fileExists(atPath: url.path) else { return nil }
|
|
46
54
|
|
|
47
|
-
let lastVersion = UserDefaults.standard.string(forKey: binaryVersionKey)
|
|
48
|
-
if let lastVersion = lastVersion, lastVersion != currentVersion {
|
|
49
|
-
print("BundleDrop: Binary updated (\(lastVersion) → \(currentVersion)), clearing OTA bundle")
|
|
50
|
-
clearOtaState(root: root)
|
|
51
|
-
UserDefaults.standard.set(currentVersion, forKey: binaryVersionKey)
|
|
52
|
-
return nil
|
|
53
|
-
}
|
|
54
|
-
|
|
55
55
|
UserDefaults.standard.set(currentVersion, forKey: binaryVersionKey)
|
|
56
56
|
return url
|
|
57
57
|
} catch {
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -14,12 +14,23 @@ async function ensureDir(dir) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
async function atomicWriteJson(path, data) {
|
|
17
|
-
const tmp = `${path}.tmp`;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
18
|
+
try {
|
|
19
|
+
await fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
20
|
+
try {
|
|
21
|
+
await fs_1.default.unlink(path);
|
|
22
|
+
}
|
|
23
|
+
catch { /* already removed by concurrent writer */ }
|
|
24
|
+
await fs_1.default.moveFile(tmp, path);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Atomic rename failed (concurrent writer moved/removed our tmp); fall back to direct write.
|
|
28
|
+
await fs_1.default.writeFile(path, JSON.stringify(data), 'utf8');
|
|
29
|
+
try {
|
|
30
|
+
await fs_1.default.unlink(tmp);
|
|
31
|
+
}
|
|
32
|
+
catch { /* clean up orphaned tmp if it exists */ }
|
|
21
33
|
}
|
|
22
|
-
await fs_1.default.moveFile(tmp, path);
|
|
23
34
|
}
|
|
24
35
|
async function ensureParentDir(filePath) {
|
|
25
36
|
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
@@ -28,11 +39,21 @@ async function ensureParentDir(filePath) {
|
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
41
|
async function writeFileAtomicBase64(path, base64) {
|
|
31
|
-
const tmp = `${path}.tmp`;
|
|
42
|
+
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
32
43
|
await ensureParentDir(path);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
try {
|
|
45
|
+
await fs_1.default.writeFile(tmp, base64, 'base64');
|
|
46
|
+
try {
|
|
47
|
+
await fs_1.default.unlink(path);
|
|
48
|
+
}
|
|
49
|
+
catch { /* already removed by concurrent writer */ }
|
|
50
|
+
await fs_1.default.moveFile(tmp, path);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
await fs_1.default.writeFile(path, base64, 'base64');
|
|
54
|
+
try {
|
|
55
|
+
await fs_1.default.unlink(tmp);
|
|
56
|
+
}
|
|
57
|
+
catch { /* clean up orphaned tmp if it exists */ }
|
|
36
58
|
}
|
|
37
|
-
await fs_1.default.moveFile(tmp, path);
|
|
38
59
|
}
|
|
@@ -126,7 +126,7 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
126
126
|
pendingApply: true,
|
|
127
127
|
runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
|
|
128
128
|
};
|
|
129
|
-
(0, bundleInfo_1.writeBundleInfo)(installedInfo);
|
|
129
|
+
await (0, bundleInfo_1.writeBundleInfo)(installedInfo);
|
|
130
130
|
await (0, bundlePointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
|
|
131
131
|
await (0, rollbackState_1.markCandidateActivated)(installedHash);
|
|
132
132
|
return { status: 'staged', bundlePath, hash: installedHash };
|
|
@@ -38,8 +38,10 @@ async function initUpdateManager(opts) {
|
|
|
38
38
|
if (pendingState.pendingApply) {
|
|
39
39
|
if (policy === 'immediate') {
|
|
40
40
|
statusCb?.('♻️ Applying previously downloaded update...');
|
|
41
|
-
await (0, updateState_1.applyUpdate)(statusCb);
|
|
42
|
-
|
|
41
|
+
const applyResult = await (0, updateState_1.applyUpdate)(statusCb);
|
|
42
|
+
if (applyResult.status === 'applied')
|
|
43
|
+
return;
|
|
44
|
+
// 'alreadyApplied' or 'noBundle' — fall through to checkForUpdate
|
|
43
45
|
}
|
|
44
46
|
if (policy === 'on-next-launch') {
|
|
45
47
|
statusCb?.('✅ Update downloaded; will apply on next launch.');
|