mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-11 08:04:23 +08:00
Merge pull request #73 from Microsoft/delete-old-packages
Delete old packages
This commit is contained in:
@@ -275,7 +275,7 @@ public class CodePush {
|
||||
savePendingUpdate(pendingHash, rollbackTimeout);
|
||||
}
|
||||
|
||||
if (installMode != CodePushInstallMode.IMMEDIATE.getValue()) {
|
||||
if (installMode == CodePushInstallMode.IMMEDIATE.getValue()) {
|
||||
loadBundle();
|
||||
} else if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue()) {
|
||||
// Ensure we do not add the listener twice.
|
||||
|
||||
@@ -170,6 +170,11 @@ public class CodePushPackage {
|
||||
public void installPackage(ReadableMap updatePackage) throws IOException {
|
||||
String packageHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
|
||||
WritableMap info = getCurrentPackageInfo();
|
||||
String previousPackageHash = getPreviousPackageHash();
|
||||
if (previousPackageHash != null && !previousPackageHash.equals(packageHash)) {
|
||||
CodePushUtils.deleteDirectoryAtPath(getPackageFolderPath(previousPackageHash));
|
||||
}
|
||||
|
||||
info.putString(PREVIOUS_PACKAGE_KEY, CodePushUtils.tryGetString(info, CURRENT_PACKAGE_KEY));
|
||||
info.putString(CURRENT_PACKAGE_KEY, packageHash);
|
||||
updateCurrentPackageInfo(info);
|
||||
|
||||
@@ -61,6 +61,27 @@ public class CodePushUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectoryAtPath(String directoryPath) {
|
||||
deleteDirectory(new File(directoryPath));
|
||||
}
|
||||
|
||||
public static void deleteDirectory(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (int i=0; i<files.length; i++) {
|
||||
if(files[i].isDirectory()) {
|
||||
deleteDirectory(files[i]);
|
||||
}
|
||||
else {
|
||||
files[i].delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
directory.delete();
|
||||
}
|
||||
|
||||
public static boolean createFolderAtPath(String filePath) {
|
||||
File file = new File(filePath);
|
||||
return file.mkdir();
|
||||
|
||||
Reference in New Issue
Block a user