@@ -7,10 +7,6 @@ @implementation CodePushUpdateUtils
7
7
NSString * const BinaryHashKey = @" CodePushBinaryHash" ;
8
8
NSString * const ManifestFolderPrefix = @" CodePush" ;
9
9
10
- // These variables are used to cache the hash of the binary contents in memory.
11
- static NSString *binaryHash = nil ;
12
- static BOOL didLoadBinaryHash = NO ;
13
-
14
10
+ (void )addContentsOfFolderToManifest : (NSString *)folderPath
15
11
pathPrefix : (NSString *)pathPrefix
16
12
manifest : (NSMutableArray *)manifest
@@ -162,49 +158,43 @@ + (NSString *)getAssetsFolderName
162
158
+ (NSString *)getHashForBinaryContents : (NSURL *)binaryBundleUrl
163
159
error : (NSError **)error
164
160
{
165
- if (!didLoadBinaryHash) {
166
- didLoadBinaryHash = YES ;
167
-
168
- // Get the cached hash from user preferences if it exists.
169
- NSString *binaryModifiedDate = [self modifiedDateStringOfFileAtURL: binaryBundleUrl];
170
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
171
- NSMutableDictionary *binaryHashDictionary = [preferences objectForKey: BinaryHashKey];
172
- if (binaryHashDictionary != nil ) {
173
- binaryHash = [binaryHashDictionary objectForKey: binaryModifiedDate];
174
- if (binaryHash == nil ) {
175
- [preferences removeObjectForKey: BinaryHashKey];
176
- [preferences synchronize ];
177
- } else {
178
- return binaryHash;
179
- }
180
- }
181
-
182
- binaryHashDictionary = [NSMutableDictionary dictionary ];
183
-
184
- NSString *assetsPath = [CodePushPackage getBinaryAssetsPath ];
185
- NSMutableArray *manifest = [NSMutableArray array ];
186
- [self addContentsOfFolderToManifest: assetsPath
187
- pathPrefix: [NSString stringWithFormat: @" %@ /%@ " , [self getManifestFolderPrefix ], @" assets" ]
188
- manifest: manifest
189
- error: error];
190
- if (*error) {
191
- return nil ;
161
+ // Get the cached hash from user preferences if it exists.
162
+ NSString *binaryModifiedDate = [self modifiedDateStringOfFileAtURL: binaryBundleUrl];
163
+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
164
+ NSMutableDictionary *binaryHashDictionary = [preferences objectForKey: BinaryHashKey];
165
+ NSString *binaryHash = nil ;
166
+ if (binaryHashDictionary != nil ) {
167
+ binaryHash = [binaryHashDictionary objectForKey: binaryModifiedDate];
168
+ if (binaryHash == nil ) {
169
+ [preferences removeObjectForKey: BinaryHashKey];
170
+ [preferences synchronize ];
171
+ } else {
172
+ return binaryHash;
192
173
}
193
-
194
- NSData *jsBundleContents = [NSData dataWithContentsOfURL: binaryBundleUrl];
195
- NSString *jsBundleContentsHash = [self computeHashForData: jsBundleContents];
196
- [manifest addObject: [[NSString stringWithFormat: @" %@ /%@ :" , [self getManifestFolderPrefix ], [binaryBundleUrl lastPathComponent ]] stringByAppendingString: jsBundleContentsHash]];
197
- binaryHash = [self computeFinalHashFromManifest: manifest error: error];
198
-
199
- // Cache the hash in user preferences. This assumes that the modified date for the
200
- // JS bundle changes every time a new bundle is generated by the packager.
201
- [binaryHashDictionary setObject: binaryHash forKey: binaryModifiedDate];
202
- [preferences setObject: binaryHashDictionary forKey: BinaryHashKey];
203
- [preferences synchronize ];
204
- return binaryHash;
205
174
}
206
175
207
- // Use the cached hash in memory.
176
+ binaryHashDictionary = [NSMutableDictionary dictionary ];
177
+
178
+ NSString *assetsPath = [CodePushPackage getBinaryAssetsPath ];
179
+ NSMutableArray *manifest = [NSMutableArray array ];
180
+ [self addContentsOfFolderToManifest: assetsPath
181
+ pathPrefix: [NSString stringWithFormat: @" %@ /%@ " , [self getManifestFolderPrefix ], @" assets" ]
182
+ manifest: manifest
183
+ error: error];
184
+ if (*error) {
185
+ return nil ;
186
+ }
187
+
188
+ NSData *jsBundleContents = [NSData dataWithContentsOfURL: binaryBundleUrl];
189
+ NSString *jsBundleContentsHash = [self computeHashForData: jsBundleContents];
190
+ [manifest addObject: [[NSString stringWithFormat: @" %@ /%@ :" , [self getManifestFolderPrefix ], [binaryBundleUrl lastPathComponent ]] stringByAppendingString: jsBundleContentsHash]];
191
+ binaryHash = [self computeFinalHashFromManifest: manifest error: error];
192
+
193
+ // Cache the hash in user preferences. This assumes that the modified date for the
194
+ // JS bundle changes every time a new bundle is generated by the packager.
195
+ [binaryHashDictionary setObject: binaryHash forKey: binaryModifiedDate];
196
+ [preferences setObject: binaryHashDictionary forKey: BinaryHashKey];
197
+ [preferences synchronize ];
208
198
return binaryHash;
209
199
}
210
200
0 commit comments