Skip to content

Commit 53497f2

Browse files
committed
Crash preventation
1 parent 0dd8dda commit 53497f2

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

Crashlytics/Crashlytics/Controllers/FIRCLSNetworkClient.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ - (BOOL)supportsBackgroundRequests {
132132

133133
- (void)attemptToReconnectBackgroundSessionWithCompletionBlock:(void (^)(void))completionBlock {
134134
if (!self.supportsBackgroundRequests) {
135-
completionBlock();
135+
if (completionBlock) {
136+
completionBlock();
137+
}
136138
return;
137139
}
138140

139141
// This is the absolute minimum necessary. Perhaps we can do better?
140-
[[NSOperationQueue mainQueue] addOperationWithBlock:completionBlock];
142+
if (completionBlock) {
143+
[[NSOperationQueue mainQueue] addOperationWithBlock:completionBlock];
144+
}
141145
}
142146

143147
#pragma mark - API

Crashlytics/Crashlytics/Models/FIRCLSFileManager.m

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ - (void)enumerateFilesInDirectory:(NSString *)directory
140140

141141
extension = [path pathExtension];
142142
fullPath = [directory stringByAppendingPathComponent:path];
143-
144-
block(fullPath, extension);
143+
if (block) {
144+
block(fullPath, extension);
145+
}
145146
}
146147
}
147148

@@ -176,7 +177,7 @@ - (NSArray *)contentsOfDirectory:(NSString *)path {
176177
[array addObject:filePath];
177178
}];
178179

179-
return array;
180+
return [array copy];
180181
}
181182

182183
#pragma - Properties
@@ -271,8 +272,9 @@ - (void)enumerateReportsInProcessingDirectoryUsingBlock:(void (^)(FIRCLSInternal
271272
usingBlock:^(NSString *filePath, NSString *extension) {
272273
FIRCLSInternalReport *report =
273274
[FIRCLSInternalReport reportWithPath:filePath];
274-
275-
block(report, filePath);
275+
if (block) {
276+
block(report, filePath);
277+
}
276278
}];
277279
}
278280

@@ -304,27 +306,14 @@ - (BOOL)removeContentsOfPendingPath {
304306

305307
- (BOOL)removeContentsOfAllPaths {
306308
BOOL success = YES;
307-
308-
// We want to call all of these methods, even if some fail, and return
309-
// NO if any fail. This turned out to be slightly tricky to do in more
310-
// compact forms, so I did it the simple but verbose way.
311-
312-
if (![self removeContentsOfProcessingPath]) {
313-
success = NO;
314-
}
315-
316-
if (![self removeContentsOfPendingPath]) {
317-
success = NO;
318-
}
319-
320-
if (![self removeContentsOfDirectoryAtPath:self.preparedPath]) {
321-
success = NO;
322-
}
323-
324-
if (![self removeContentsOfDirectoryAtPath:self.activePath]) {
325-
success = NO;
326-
}
327-
309+
BOOL contentsOfProcessingPathRemoved = [self removeContentsOfProcessingPath];
310+
BOOL contentsOfPendingPathRemoved = [self removeContentsOfPendingPath];
311+
BOOL contentsOfDirectoryAtPreparedPathRemoved =
312+
[self removeContentsOfDirectoryAtPath:self.preparedPath];
313+
BOOL contentsOfDirectoryAtActivePathRemoved =
314+
[self removeContentsOfDirectoryAtPath:self.activePath];
315+
success = contentsOfProcessingPathRemoved && contentsOfPendingPathRemoved &&
316+
contentsOfDirectoryAtPreparedPathRemoved && contentsOfDirectoryAtActivePathRemoved;
328317
return success;
329318
}
330319

0 commit comments

Comments
 (0)