Skip to content

Commit f07fcfb

Browse files
committed
Merge pull request #73 from Microsoft/delete-old-packages
Delete old packages
2 parents 3594c0b + d2cf605 commit f07fcfb

File tree

10 files changed

+43
-8
lines changed

10 files changed

+43
-8
lines changed

AlertAdapter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var Platform = require("Platform");
3+
var { Platform } = require("react-native");
44
var Alert;
55

66
if (Platform.OS === "android") {

CodePush.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
218218
"$(SRCROOT)/node_modules/react-native/React/**",
219219
"$(SRCROOT)/Examples/CodePushDemoApp/node_modules/react-native/React/**",
220+
"$(SRCROOT)/../react-native/React/**",
220221
);
221222
LIBRARY_SEARCH_PATHS = "$(inherited)";
222223
OTHER_LDFLAGS = "-ObjC";
@@ -233,6 +234,7 @@
233234
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
234235
"$(SRCROOT)/node_modules/react-native/React/**",
235236
"$(SRCROOT)/Examples/CodePushDemoApp/node_modules/react-native/React/**",
237+
"$(SRCROOT)/../react-native/React/**",
236238
);
237239
LIBRARY_SEARCH_PATHS = "$(inherited)";
238240
OTHER_LDFLAGS = "-ObjC";

CodePushPackage.m

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ + (void)installPackage:(NSDictionary *)updatePackage
218218
return;
219219
}
220220

221+
NSString *previousPackageHash = [self getPreviousPackageHash:error];
222+
if (!*error && previousPackageHash && ![previousPackageHash isEqualToString:packageHash]) {
223+
NSString *previousPackageFolderPath = [self getPackageFolderPath:previousPackageHash];
224+
[[NSFileManager defaultManager] removeItemAtPath:previousPackageFolderPath error:error];
225+
if (*error) {
226+
return;
227+
}
228+
}
229+
221230
[info setValue:info[@"currentPackage"] forKey:@"previousPackage"];
222231
[info setValue:packageHash forKey:@"currentPackage"];
223232

Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTest.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"use strict";
22

33
var React = require("react-native");
4-
var { DeviceEventEmitter } = require("react-native");
4+
var { Platform, DeviceEventEmitter } = require("react-native");
55
var CodePushSdk = require("react-native-code-push");
66
var NativeCodePush = require("react-native").NativeModules.CodePush;
77
var RCTTestModule = require('NativeModules').TestModule || {};
8-
var Platform = require("Platform");
98

109
var {
1110
Text,

Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/TestPackages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Platform = require("Platform");
1+
var { Platform } = require("react-native");
22

33
var packages = {
44
smallPackage: {

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/TestPackage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Platform = require("Platform");
1+
var { Platform } = require("react-native");
22

33
var testPackage = {
44
description: "Angry flappy birds",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void installUpdate(ReadableMap updatePackage, int rollbackTimeout, int in
275275
savePendingUpdate(pendingHash, rollbackTimeout);
276276
}
277277

278-
if (installMode != CodePushInstallMode.IMMEDIATE.getValue()) {
278+
if (installMode == CodePushInstallMode.IMMEDIATE.getValue()) {
279279
loadBundle();
280280
} else if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue()) {
281281
// Ensure we do not add the listener twice.

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

+5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public void downloadPackage(Context applicationContext, ReadableMap updatePackag
170170
public void installPackage(ReadableMap updatePackage) throws IOException {
171171
String packageHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
172172
WritableMap info = getCurrentPackageInfo();
173+
String previousPackageHash = getPreviousPackageHash();
174+
if (previousPackageHash != null && !previousPackageHash.equals(packageHash)) {
175+
CodePushUtils.deleteDirectoryAtPath(getPackageFolderPath(previousPackageHash));
176+
}
177+
173178
info.putString(PREVIOUS_PACKAGE_KEY, CodePushUtils.tryGetString(info, CURRENT_PACKAGE_KEY));
174179
info.putString(CURRENT_PACKAGE_KEY, packageHash);
175180
updateCurrentPackageInfo(info);

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

+21
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ public static void writeStringToFile(String content, String filePath) throws IOE
6161
}
6262
}
6363

64+
public static void deleteDirectoryAtPath(String directoryPath) {
65+
deleteDirectory(new File(directoryPath));
66+
}
67+
68+
public static void deleteDirectory(File directory) {
69+
if (directory.exists()) {
70+
File[] files = directory.listFiles();
71+
if (files != null) {
72+
for (int i=0; i<files.length; i++) {
73+
if(files[i].isDirectory()) {
74+
deleteDirectory(files[i]);
75+
}
76+
else {
77+
files[i].delete();
78+
}
79+
}
80+
}
81+
}
82+
directory.delete();
83+
}
84+
6485
public static boolean createFolderAtPath(String filePath) {
6586
File file = new File(filePath);
6687
return file.mkdir();

package-mixins.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var Platform = require("Platform");
2-
var { DeviceEventEmitter } = require("react-native");
1+
var { Platform, DeviceEventEmitter } = require("react-native");
32

43
module.exports = (NativeCodePush) => {
54
var remote = {

0 commit comments

Comments
 (0)