clear updates on new binary

This commit is contained in:
Geoffrey Goh
2015-12-22 12:13:32 -08:00
parent 35945e9fba
commit a2cbdab91b
8 changed files with 34 additions and 33 deletions

View File

@@ -25,7 +25,7 @@
// The below methods are only used during tests.
+ (BOOL)isUsingTestConfiguration;
+ (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration;
+ (void)clearTestUpdates;
+ (void)clearUpdates;
@end
@@ -84,7 +84,7 @@ failCallback:(void (^)(NSError *err))failCallback;
// The below methods are only used during tests.
+ (void)downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl;
+ (void)clearTestUpdates;
+ (void)clearUpdates;
@end

View File

@@ -61,13 +61,16 @@ static NSString *const PackageIsPendingKey = @"isPending";
NSDictionary *appFileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:packageFile error:nil];
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
NSDate *packageDate = [appFileAttribs objectForKey:NSFileModificationDate];
NSString *binaryAppVersion = [[CodePushConfig current] appVersion];
NSString *packageAppVersion = [appFileAttribs objectForKey:@"appVersion"];
if ([binaryDate compare:packageDate] == NSOrderedAscending) {
if ([binaryDate compare:packageDate] == NSOrderedAscending && [binaryAppVersion isEqualToString:packageAppVersion]) {
// Return package file because it is newer than the app store binary's JS bundle
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
NSLog(logMessageFormat, packageUrl);
return packageUrl;
} else {
[CodePush clearUpdates];
NSLog(logMessageFormat, binaryJsBundleUrl);
return binaryJsBundleUrl;
}
@@ -100,16 +103,12 @@ static NSString *const PackageIsPendingKey = @"isPending";
}
/*
* This is used to clean up all test updates. It can only be used
* when the testConfigurationFlag is set to YES, otherwise it will
* simply no-op.
* WARNING: This cleans up all downloaded and pending updates.
*/
+ (void)clearTestUpdates
+ (void)clearUpdates
{
if ([CodePush isUsingTestConfiguration]) {
[CodePushPackage clearTestUpdates];
[self removePendingUpdate];
}
[CodePushPackage clearUpdates];
[self removePendingUpdate];
}

View File

@@ -505,12 +505,10 @@ NSString * const UnzippedFolderName = @"unzipped";
}
}
+ (void)clearTestUpdates
+ (void)clearUpdates
{
if ([CodePush isUsingTestConfiguration]) {
[[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil];
[[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil];
}
[[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil];
[[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil];
}
@end

View File

@@ -25,7 +25,7 @@
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
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);
[CodePush setUsingTestConfiguration:YES];
[CodePush clearTestUpdates];
[CodePush clearUpdates];
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp", nil);
}

View File

@@ -25,7 +25,7 @@
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
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);
[CodePush setUsingTestConfiguration:YES];
[CodePush clearTestUpdates];
[CodePush clearUpdates];
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp", nil);
}

View File

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

View File

@@ -130,13 +130,21 @@ public class CodePush {
}
ReadableMap packageMetadata = codePushPackage.getCurrentPackage();
// May throw NumberFormatException.
Long binaryModifiedDateDuringPackageInstall = Long.parseLong(CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY));
if (binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime) {
Long binaryModifiedDateDuringPackageInstall = null;
String binaryModifiedDateDuringPackageInstallString = CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY);
if (binaryModifiedDateDuringPackageInstallString != null) {
binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString);
}
String pacakgeAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
if (binaryModifiedDateDuringPackageInstall != null &&
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
this.appVersion.equals(pacakgeAppVersion)) {
CodePushUtils.logBundleUrl(packageFilePath);
return packageFilePath;
} else {
// The binary version is newer.
CodePushUtils.logBundleUrl(binaryJsBundleUrl);
return binaryJsBundleUrl;
}
@@ -299,11 +307,9 @@ public class CodePush {
testConfigurationFlag = shouldUseTestConfiguration;
}
public void clearTestUpdates() {
if (isUsingTestConfiguration()) {
codePushPackage.clearTestUpdates();
removePendingUpdate();
}
public void clearUpdates() {
codePushPackage.clearUpdates();
removePendingUpdate();
}
private class CodePushNativeModule extends ReactContextBaseJavaModule {

View File

@@ -225,11 +225,9 @@ public class CodePushPackage {
}
}
public void clearTestUpdates() {
if (CodePush.isUsingTestConfiguration()) {
File statusFile = new File(getStatusFilePath());
statusFile.delete();
CodePushUtils.deleteDirectoryAtPath(getCodePushPath());
}
public void clearUpdates() {
File statusFile = new File(getStatusFilePath());
statusFile.delete();
CodePushUtils.deleteDirectoryAtPath(getCodePushPath());
}
}