From eee43ecc23cc83f6d24437654db18bc7c6d9e87c Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Sat, 12 Mar 2016 14:56:30 -0800 Subject: [PATCH 1/2] Fix bundle location --- ios/CodePush/CodePush.h | 2 ++ ios/CodePush/CodePush.m | 4 +++- ios/CodePush/CodePushPackage.m | 3 +++ ios/CodePush/CodePushUpdateUtils.m | 9 +++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ios/CodePush/CodePush.h b/ios/CodePush/CodePush.h index bd7db3c..1760715 100644 --- a/ios/CodePush/CodePush.h +++ b/ios/CodePush/CodePush.h @@ -70,6 +70,7 @@ failCallback:(void (^)(NSError *err))failCallback; @interface CodePushPackage : NSObject + (void)downloadPackage:(NSDictionary *)updatePackage + expectedBundleFileName:(NSString *)expectedBundleFileName progressCallback:(void (^)(long long, long long))progressCallback doneCallback:(void (^)())doneCallback failCallback:(void (^)(NSError *err))failCallback; @@ -113,6 +114,7 @@ failCallback:(void (^)(NSError *err))failCallback; error:(NSError **)error; + (NSString *)findMainBundleInFolder:(NSString *)folderPath + expectedFileName:(NSString *)expectedFileName error:(NSError **)error; + (NSString *)assetsFolderName; diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index 68141c6..d016e8d 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -419,7 +419,9 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage forKey:BinaryBundleDateKey]; } - [CodePushPackage downloadPackage:mutableUpdatePackage + [CodePushPackage + downloadPackage:mutableUpdatePackage + expectedBundleFileName:[bundleResourceName stringByAppendingPathExtension:bundleResourceExtension] // The download is progressing forward progressCallback:^(long long expectedContentLength, long long receivedContentLength) { dispatch_async(_methodQueue, ^{ diff --git a/ios/CodePush/CodePushPackage.m b/ios/CodePush/CodePushPackage.m index 9699f09..979bd34 100644 --- a/ios/CodePush/CodePushPackage.m +++ b/ios/CodePush/CodePushPackage.m @@ -205,6 +205,7 @@ NSString * const UnzippedFolderName = @"unzipped"; } + (void)downloadPackage:(NSDictionary *)updatePackage + expectedBundleFileName:(NSString *)expectedBundleFileName progressCallback:(void (^)(long long, long long))progressCallback doneCallback:(void (^)())doneCallback failCallback:(void (^)(NSError *err))failCallback @@ -360,7 +361,9 @@ NSString * const UnzippedFolderName = @"unzipped"; } NSString *relativeBundlePath = [CodePushUpdateUtils findMainBundleInFolder:newUpdateFolderPath + expectedFileName:expectedBundleFileName error:&error]; + if (error) { failCallback(error); return; diff --git a/ios/CodePush/CodePushUpdateUtils.m b/ios/CodePush/CodePushUpdateUtils.m index 29c199f..ca541f7 100644 --- a/ios/CodePush/CodePushUpdateUtils.m +++ b/ios/CodePush/CodePushUpdateUtils.m @@ -118,6 +118,7 @@ NSString * const ManifestFolderPrefix = @"CodePush"; } + (NSString *)findMainBundleInFolder:(NSString *)folderPath + expectedFileName:(NSString *)expectedFileName error:(NSError **)error { NSArray* folderFiles = [[NSFileManager defaultManager] @@ -132,7 +133,9 @@ NSString * const ManifestFolderPrefix = @"CodePush"; BOOL isDir = NO; if ([[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDir] && isDir) { - NSString *mainBundlePathInFolder = [self findMainBundleInFolder:fullFilePath error:error]; + NSString *mainBundlePathInFolder = [self findMainBundleInFolder:fullFilePath + expectedFileName:expectedFileName + error:error]; if (*error) { return nil; } @@ -140,9 +143,7 @@ NSString * const ManifestFolderPrefix = @"CodePush"; if (mainBundlePathInFolder) { return [fileName stringByAppendingPathComponent:mainBundlePathInFolder]; } - } else if ([[fileName pathExtension] isEqualToString:@"bundle"] || - [[fileName pathExtension] isEqualToString:@"jsbundle"] || - [[fileName pathExtension] isEqualToString:@"js"]) { + } else if ([fileName isEqualToString:expectedFileName]) { return fileName; } } From e27968e32ebbdf8b50abc1b76f8e0b8e768508fe Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Sat, 12 Mar 2016 15:15:40 -0800 Subject: [PATCH 2/2] Android implementation --- .../java/com/microsoft/codepush/react/CodePush.java | 2 +- .../microsoft/codepush/react/CodePushPackage.java | 4 ++-- .../codepush/react/CodePushUpdateUtils.java | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 2ac9e48..edced16 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -365,7 +365,7 @@ public class CodePush { try { WritableMap mutableUpdatePackage = CodePushUtils.convertReadableMapToWritableMap(updatePackage); mutableUpdatePackage.putString(BINARY_MODIFIED_TIME_KEY, "" + getBinaryResourcesModifiedTime()); - codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, new DownloadProgressCallback() { + codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, CodePush.this.assetsBundleFileName, new DownloadProgressCallback() { @Override public void call(DownloadProgress downloadProgress) { getReactApplicationContext() diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java index 60a9569..a5c8f84 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java @@ -151,7 +151,7 @@ public class CodePushPackage { } } - public void downloadPackage(Context applicationContext, ReadableMap updatePackage, + public void downloadPackage(Context applicationContext, ReadableMap updatePackage, String expectedBundleFileName, DownloadProgressCallback progressCallback) throws IOException { String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY); String newUpdateFolderPath = getPackageFolderPath(newUpdateHash); @@ -243,7 +243,7 @@ public class CodePushPackage { // For zip updates, we need to find the relative path to the jsBundle and save it in the // metadata so that we can find and run it easily the next time. - String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath); + String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName); if (relativeBundlePath == null) { throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package."); diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java index f30e188..99dde10 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java @@ -79,24 +79,20 @@ public class CodePushUpdateUtils { } } - public static String findJSBundleInUpdateContents(String folderPath) { + public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) { File folder = new File(folderPath); File[] folderFiles = folder.listFiles(); for (File file : folderFiles) { String fullFilePath = CodePushUtils.appendPathComponent(folderPath, file.getName()); if (file.isDirectory()) { - String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath); + String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath, expectedFileName); if (mainBundlePathInSubFolder != null) { return CodePushUtils.appendPathComponent(file.getName(), mainBundlePathInSubFolder); } } else { String fileName = file.getName(); - int dotIndex = fileName.lastIndexOf("."); - if (dotIndex >= 0) { - String fileExtension = fileName.substring(dotIndex + 1); - if (fileExtension.equals("bundle") || fileExtension.equals("js") || fileExtension.equals("jsbundle")) { - return fileName; - } + if (fileName.equals(expectedFileName)) { + return fileName; } } }