mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-14 02:14:52 +08:00
clear updates on new binary
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
17
CodePush.m
17
CodePush.m
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user