Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 2733af7

Browse files
committed
fix android install to overwrite pending
1 parent e34f514 commit 2733af7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public void installUpdate(final ReadableMap updatePackage, final int installMode
481481
@Override
482482
protected Void doInBackground(Object... params) {
483483
try {
484-
codePushPackage.installPackage(updatePackage);
484+
codePushPackage.installPackage(updatePackage, isPendingUpdate(null));
485485

486486
String pendingHash = CodePushUtils.tryGetString(updatePackage, codePushPackage.PACKAGE_HASH_KEY);
487487
if (pendingHash == null) {

android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,23 @@ public void downloadPackage(Context applicationContext, ReadableMap updatePackag
259259
CodePushUtils.writeReadableMapToFile(updatePackage, bundlePath);
260260
}
261261

262-
public void installPackage(ReadableMap updatePackage) throws IOException {
262+
public void installPackage(ReadableMap updatePackage, boolean removePendingUpdate) throws IOException {
263263
String packageHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
264264
WritableMap info = getCurrentPackageInfo();
265-
String previousPackageHash = getPreviousPackageHash();
266-
if (previousPackageHash != null && !previousPackageHash.equals(packageHash)) {
267-
FileUtils.deleteDirectoryAtPath(getPackageFolderPath(previousPackageHash));
265+
if (removePendingUpdate) {
266+
String currentPackageFolderPath = getCurrentPackageFolderPath();
267+
if (currentPackageFolderPath != null) {
268+
FileUtils.deleteDirectoryAtPath(currentPackageFolderPath);
269+
}
270+
} else {
271+
String previousPackageHash = getPreviousPackageHash();
272+
if (previousPackageHash != null && !previousPackageHash.equals(packageHash)) {
273+
FileUtils.deleteDirectoryAtPath(getPackageFolderPath(previousPackageHash));
274+
}
275+
276+
info.putString(PREVIOUS_PACKAGE_KEY, CodePushUtils.tryGetString(info, CURRENT_PACKAGE_KEY));
268277
}
269278

270-
info.putString(PREVIOUS_PACKAGE_KEY, CodePushUtils.tryGetString(info, CURRENT_PACKAGE_KEY));
271279
info.putString(CURRENT_PACKAGE_KEY, packageHash);
272280
updateCurrentPackageInfo(info);
273281
}

0 commit comments

Comments
 (0)