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

Commit a2cbdab

Browse files
committed
clear updates on new binary
1 parent 35945e9 commit a2cbdab

File tree

8 files changed

+34
-33
lines changed

8 files changed

+34
-33
lines changed

CodePush.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// The below methods are only used during tests.
2626
+ (BOOL)isUsingTestConfiguration;
2727
+ (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration;
28-
+ (void)clearTestUpdates;
28+
+ (void)clearUpdates;
2929

3030
@end
3131

@@ -84,7 +84,7 @@ failCallback:(void (^)(NSError *err))failCallback;
8484

8585
// The below methods are only used during tests.
8686
+ (void)downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl;
87-
+ (void)clearTestUpdates;
87+
+ (void)clearUpdates;
8888

8989
@end
9090

CodePush.m

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
6161
NSDictionary *appFileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:packageFile error:nil];
6262
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
6363
NSDate *packageDate = [appFileAttribs objectForKey:NSFileModificationDate];
64+
NSString *binaryAppVersion = [[CodePushConfig current] appVersion];
65+
NSString *packageAppVersion = [appFileAttribs objectForKey:@"appVersion"];
6466

65-
if ([binaryDate compare:packageDate] == NSOrderedAscending) {
67+
if ([binaryDate compare:packageDate] == NSOrderedAscending && [binaryAppVersion isEqualToString:packageAppVersion]) {
6668
// Return package file because it is newer than the app store binary's JS bundle
6769
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
6870
NSLog(logMessageFormat, packageUrl);
6971
return packageUrl;
7072
} else {
73+
[CodePush clearUpdates];
7174
NSLog(logMessageFormat, binaryJsBundleUrl);
7275
return binaryJsBundleUrl;
7376
}
@@ -100,16 +103,12 @@ + (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration
100103
}
101104

102105
/*
103-
* This is used to clean up all test updates. It can only be used
104-
* when the testConfigurationFlag is set to YES, otherwise it will
105-
* simply no-op.
106+
* WARNING: This cleans up all downloaded and pending updates.
106107
*/
107-
+ (void)clearTestUpdates
108+
+ (void)clearUpdates
108109
{
109-
if ([CodePush isUsingTestConfiguration]) {
110-
[CodePushPackage clearTestUpdates];
111-
[self removePendingUpdate];
112-
}
110+
[CodePushPackage clearUpdates];
111+
[self removePendingUpdate];
113112
}
114113

115114

CodePushPackage.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,10 @@ + (void)downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl
505505
}
506506
}
507507

508-
+ (void)clearTestUpdates
508+
+ (void)clearUpdates
509509
{
510-
if ([CodePush isUsingTestConfiguration]) {
511-
[[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil];
512-
[[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil];
513-
}
510+
[[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil];
511+
[[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil];
514512
}
515513

516514
@end

Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (void)setUp
2525
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
2626
RCTAssert(version.majorVersion == 8 || version.minorVersion == 3, @"Tests should be run on iOS 8.3, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion);
2727
[CodePush setUsingTestConfiguration:YES];
28-
[CodePush clearTestUpdates];
28+
[CodePush clearUpdates];
2929
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp", nil);
3030
}
3131

Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (void)setUp
2525
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
2626
RCTAssert(version.majorVersion == 8 || version.minorVersion == 3, @"Tests should be run on iOS 8.3, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion);
2727
[CodePush setUsingTestConfiguration:YES];
28-
[CodePush clearTestUpdates];
28+
[CodePush clearUpdates];
2929
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp", nil);
3030
}
3131

Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ - (void)testIsPending
7272

7373
- (void)runTest:(NSString *)testName
7474
{
75-
[CodePush clearTestUpdates];
75+
[CodePush clearUpdates];
7676
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/testcases/%@.bundle?platform=ios&dev=true", testName]]
7777
moduleName:testName
7878
initialProperties:nil

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,21 @@ public String getBundleUrl(String assetsBundleFileName) {
130130
}
131131

132132
ReadableMap packageMetadata = codePushPackage.getCurrentPackage();
133-
// May throw NumberFormatException.
134-
Long binaryModifiedDateDuringPackageInstall = Long.parseLong(CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY));
135-
if (binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime) {
133+
Long binaryModifiedDateDuringPackageInstall = null;
134+
String binaryModifiedDateDuringPackageInstallString = CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY);
135+
if (binaryModifiedDateDuringPackageInstallString != null) {
136+
binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString);
137+
}
138+
139+
String pacakgeAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
140+
if (binaryModifiedDateDuringPackageInstall != null &&
141+
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
142+
this.appVersion.equals(pacakgeAppVersion)) {
136143
CodePushUtils.logBundleUrl(packageFilePath);
137144
return packageFilePath;
138145
} else {
139146
// The binary version is newer.
147+
140148
CodePushUtils.logBundleUrl(binaryJsBundleUrl);
141149
return binaryJsBundleUrl;
142150
}
@@ -299,11 +307,9 @@ public static void setUsingTestConfiguration(boolean shouldUseTestConfiguration)
299307
testConfigurationFlag = shouldUseTestConfiguration;
300308
}
301309

302-
public void clearTestUpdates() {
303-
if (isUsingTestConfiguration()) {
304-
codePushPackage.clearTestUpdates();
305-
removePendingUpdate();
306-
}
310+
public void clearUpdates() {
311+
codePushPackage.clearUpdates();
312+
removePendingUpdate();
307313
}
308314

309315
private class CodePushNativeModule extends ReactContextBaseJavaModule {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,9 @@ public void downloadAndReplaceCurrentBundle(String remoteBundleUrl) throws IOExc
225225
}
226226
}
227227

228-
public void clearTestUpdates() {
229-
if (CodePush.isUsingTestConfiguration()) {
230-
File statusFile = new File(getStatusFilePath());
231-
statusFile.delete();
232-
CodePushUtils.deleteDirectoryAtPath(getCodePushPath());
233-
}
228+
public void clearUpdates() {
229+
File statusFile = new File(getStatusFilePath());
230+
statusFile.delete();
231+
CodePushUtils.deleteDirectoryAtPath(getCodePushPath());
234232
}
235233
}

0 commit comments

Comments
 (0)