Skip to content

Commit

Permalink
Merge pull request #73 from Microsoft/delete-old-packages
Browse files Browse the repository at this point in the history
Delete old packages
  • Loading branch information
geof90 committed Nov 26, 2015
2 parents 3594c0b + d2cf605 commit f07fcfb
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion AlertAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Platform = require("Platform");
var { Platform } = require("react-native");
var Alert;

if (Platform.OS === "android") {
Expand Down
2 changes: 2 additions & 0 deletions CodePush.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/node_modules/react-native/React/**",
"$(SRCROOT)/Examples/CodePushDemoApp/node_modules/react-native/React/**",
"$(SRCROOT)/../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand All @@ -233,6 +234,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/node_modules/react-native/React/**",
"$(SRCROOT)/Examples/CodePushDemoApp/node_modules/react-native/React/**",
"$(SRCROOT)/../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand Down
9 changes: 9 additions & 0 deletions CodePushPackage.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ + (void)installPackage:(NSDictionary *)updatePackage
return;
}

NSString *previousPackageHash = [self getPreviousPackageHash:error];
if (!*error && previousPackageHash && ![previousPackageHash isEqualToString:packageHash]) {
NSString *previousPackageFolderPath = [self getPackageFolderPath:previousPackageHash];
[[NSFileManager defaultManager] removeItemAtPath:previousPackageFolderPath error:error];
if (*error) {
return;
}
}

[info setValue:info[@"currentPackage"] forKey:@"previousPackage"];
[info setValue:packageHash forKey:@"currentPackage"];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";

var React = require("react-native");
var { DeviceEventEmitter } = require("react-native");
var { Platform, DeviceEventEmitter } = require("react-native");
var CodePushSdk = require("react-native-code-push");
var NativeCodePush = require("react-native").NativeModules.CodePush;
var RCTTestModule = require('NativeModules').TestModule || {};
var Platform = require("Platform");

var {
Text,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Platform = require("Platform");
var { Platform } = require("react-native");

var packages = {
smallPackage: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Platform = require("Platform");
var { Platform } = require("react-native");

var testPackage = {
description: "Angry flappy birds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void installUpdate(ReadableMap updatePackage, int rollbackTimeout, int in
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public void downloadPackage(Context applicationContext, ReadableMap updatePackag
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ public static void writeStringToFile(String content, String filePath) throws IOE
}
}

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();
Expand Down
3 changes: 1 addition & 2 deletions package-mixins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Platform = require("Platform");
var { DeviceEventEmitter } = require("react-native");
var { Platform, DeviceEventEmitter } = require("react-native");

module.exports = (NativeCodePush) => {
var remote = {
Expand Down

0 comments on commit f07fcfb

Please sign in to comment.