From fcc05c65f8766069398413f954b5f7db04a15ca5 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 24 Jun 2016 14:47:31 -0700 Subject: [PATCH] Binary hash ios --- ios/CodePush/CodePushUpdateUtils.m | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ios/CodePush/CodePushUpdateUtils.m b/ios/CodePush/CodePushUpdateUtils.m index 334ea87..48270e0 100644 --- a/ios/CodePush/CodePushUpdateUtils.m +++ b/ios/CodePush/CodePushUpdateUtils.m @@ -40,6 +40,16 @@ NSString * const ManifestFolderPrefix = @"CodePush"; } } ++ (void)addFileToManifest:(NSURL *)fileURL + manifest:(NSMutableArray *)manifest +{ + if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) { + NSData *fileContents = [NSData dataWithContentsOfURL:fileURL]; + NSString *fileContentsHash = [self computeHashForData:fileContents]; + [manifest addObject:[NSString stringWithFormat:@"%@/%@:%@", [self manifestFolderPrefix], [fileURL lastPathComponent], fileContentsHash]]; + } +} + + (NSString *)computeFinalHashFromManifest:(NSMutableArray *)manifest error:(NSError **)error { @@ -190,9 +200,9 @@ NSString * const ManifestFolderPrefix = @"CodePush"; } } - NSData *jsBundleContents = [NSData dataWithContentsOfURL:binaryBundleUrl]; - NSString *jsBundleContentsHash = [self computeHashForData:jsBundleContents]; - [manifest addObject:[[NSString stringWithFormat:@"%@/%@:", [self manifestFolderPrefix], [binaryBundleUrl lastPathComponent]] stringByAppendingString:jsBundleContentsHash]]; + [self addFileToManifest:binaryBundleUrl manifest:manifest]; + [self addFileToManifest:[binaryBundleUrl URLByAppendingPathExtension:@"meta"] manifest:manifest]; + binaryHash = [self computeFinalHashFromManifest:manifest error:error]; // Cache the hash in user preferences. This assumes that the modified date for the