From a06b677af0db5f27d7b8d6b45198e1ee8f25b59d Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 3 Dec 2015 11:54:28 -0800 Subject: [PATCH] feedback --- CodePushDownloadHandler.m | 10 +++++----- CodePushPackage.m | 31 +++++++++++++------------------ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/CodePushDownloadHandler.m b/CodePushDownloadHandler.m index fb6dd69..f7f88dc 100644 --- a/CodePushDownloadHandler.m +++ b/CodePushDownloadHandler.m @@ -2,7 +2,7 @@ @implementation CodePushDownloadHandler { // Header chars used to determine if the file is a zip. - char header[4]; + char _header[4]; } - (id)init:(NSString *)downloadFilePath @@ -46,14 +46,14 @@ failCallback:(void (^)(NSError *err))failCallback { -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { if (self.receivedContentLength < 4) { - const char *bytes = [data bytes]; - for (int i=0; i<[data length]; i++) { + for (int i = 0; i < [data length]; i++) { int headerOffset = (int)self.receivedContentLength + i; if (headerOffset >= 4) { break; } - header[headerOffset] = bytes[i]; + const char *bytes = [data bytes]; + _header[headerOffset] = bytes[i]; } } @@ -94,7 +94,7 @@ failCallback:(void (^)(NSError *err))failCallback { assert(self.receivedContentLength == self.expectedContentLength); [self.outputFileStream close]; - BOOL isZip = header[0] == 'P' && header[1] == 'K' && header[2] == 3 && header[3] == 4; + BOOL isZip = _header[0] == 'P' && _header[1] == 'K' && _header[2] == 3 && _header[3] == 4; self.doneCallback(isZip); } diff --git a/CodePushPackage.m b/CodePushPackage.m index 56a8789..f4c1298 100644 --- a/CodePushPackage.m +++ b/CodePushPackage.m @@ -207,8 +207,8 @@ NSString * const UnzippedFolderName = @"unzipped"; return failCallback(error); } - NSString * downloadFilePath = [self getDownloadFilePath]; - NSString * bundleFilePath = [newPackageFolderPath stringByAppendingPathComponent:UpdateBundleFileName]; + NSString *downloadFilePath = [self getDownloadFilePath]; + NSString *bundleFilePath = [newPackageFolderPath stringByAppendingPathComponent:UpdateBundleFileName]; CodePushDownloadHandler *downloadHandler = [[CodePushDownloadHandler alloc] init:downloadFilePath @@ -229,12 +229,11 @@ NSString * const UnzippedFolderName = @"unzipped"; nonFailingError = nil; } - NSString * diffManifestFilePath = [unzippedFolderPath - stringByAppendingPathComponent:DiffManifestFileName]; + NSString *diffManifestFilePath = [unzippedFolderPath stringByAppendingPathComponent:DiffManifestFileName]; if ([[NSFileManager defaultManager] fileExistsAtPath:diffManifestFilePath]) { // Copy the current package to the new package. - NSString* currentPackageFolderPath = [self getCurrentPackageFolderPath:&error]; + NSString *currentPackageFolderPath = [self getCurrentPackageFolderPath:&error]; if (error) { failCallback(error); return; @@ -258,15 +257,13 @@ NSString * const UnzippedFolderName = @"unzipped"; } NSData *data = [manifestContent dataUsingEncoding:NSUTF8StringEncoding]; - NSDictionary* manifestJSON = [NSJSONSerialization JSONObjectWithData:data + NSDictionary *manifestJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSArray *deletedFiles = manifestJSON[@"deletedFiles"]; for (NSString *deletedFileName in deletedFiles) { - [[NSFileManager defaultManager] - removeItemAtPath:[newPackageFolderPath - stringByAppendingPathComponent:deletedFileName] - error:&nonFailingError]; + [[NSFileManager defaultManager] removeItemAtPath:[newPackageFolderPath stringByAppendingPathComponent:deletedFileName] + error:&nonFailingError]; if (nonFailingError) { NSLog(@"Error deleting file from current package: %@", nonFailingError); @@ -286,7 +283,7 @@ NSString * const UnzippedFolderName = @"unzipped"; } NSString *relativeBundlePath = [self findMainBundleInFolder:newPackageFolderPath - error:&error]; + error:&error]; if (error) { failCallback(error); return; @@ -314,13 +311,11 @@ NSString * const UnzippedFolderName = @"unzipped"; } } - NSData *updateSerializedData = [NSJSONSerialization - dataWithJSONObject:mutableUpdatePackage - options:0 - error:&error]; - NSString *packageJsonString = [[NSString alloc] - initWithData:updateSerializedData - encoding:NSUTF8StringEncoding]; + NSData *updateSerializedData = [NSJSONSerialization dataWithJSONObject:mutableUpdatePackage + options:0 + error:&error]; + NSString *packageJsonString = [[NSString alloc] initWithData:updateSerializedData + encoding:NSUTF8StringEncoding]; [packageJsonString writeToFile:[newPackageFolderPath stringByAppendingPathComponent:@"app.json"] atomically:YES