Merge pull request #73 from Microsoft/delete-old-packages

Delete old packages
This commit is contained in:
Geoffrey Goh
2015-11-25 18:36:27 -08:00
10 changed files with 43 additions and 8 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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();