Performing getSize and getDiskCount on the ioQueue.
Showing
1 changed file
with
8 additions
and
5 deletions
@@ -441,23 +441,26 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { | @@ -441,23 +441,26 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { | ||
441 | } | 441 | } |
442 | 442 | ||
443 | - (NSUInteger)getSize { | 443 | - (NSUInteger)getSize { |
444 | - NSUInteger size = 0; | ||
445 | - NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath]; | 444 | + __block NSUInteger size = 0; |
445 | + dispatch_sync(self.ioQueue, ^{ | ||
446 | + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; | ||
446 | for (NSString *fileName in fileEnumerator) { | 447 | for (NSString *fileName in fileEnumerator) { |
447 | NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; | 448 | NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; |
448 | NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; | 449 | NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; |
449 | size += [attrs fileSize]; | 450 | size += [attrs fileSize]; |
450 | } | 451 | } |
452 | + }); | ||
451 | return size; | 453 | return size; |
452 | } | 454 | } |
453 | 455 | ||
454 | - (int)getDiskCount { | 456 | - (int)getDiskCount { |
455 | - int count = 0; | ||
456 | - NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath]; | 457 | + __block int count = 0; |
458 | + dispatch_sync(self.ioQueue, ^{ | ||
459 | + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; | ||
457 | for (__unused NSString *fileName in fileEnumerator) { | 460 | for (__unused NSString *fileName in fileEnumerator) { |
458 | count += 1; | 461 | count += 1; |
459 | } | 462 | } |
460 | - | 463 | + }); |
461 | return count; | 464 | return count; |
462 | } | 465 | } |
463 | 466 |
-
Please register or login to post a comment