Skip to content

Commit 63f5c97

Browse files
committed
Performing getSize and getDiskCount on the ioQueue.
1 parent 1c463ad commit 63f5c97

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

SDWebImage/SDImageCache.m

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,23 +441,26 @@ - (void)backgroundCleanDisk {
441441
}
442442

443443
- (NSUInteger)getSize {
444-
NSUInteger size = 0;
445-
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];
446-
for (NSString *fileName in fileEnumerator) {
447-
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
448-
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
449-
size += [attrs fileSize];
450-
}
444+
__block NSUInteger size = 0;
445+
dispatch_sync(self.ioQueue, ^{
446+
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
447+
for (NSString *fileName in fileEnumerator) {
448+
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
449+
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
450+
size += [attrs fileSize];
451+
}
452+
});
451453
return size;
452454
}
453455

454456
- (int)getDiskCount {
455-
int count = 0;
456-
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];
457-
for (__unused NSString *fileName in fileEnumerator) {
458-
count += 1;
459-
}
460-
457+
__block int count = 0;
458+
dispatch_sync(self.ioQueue, ^{
459+
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
460+
for (__unused NSString *fileName in fileEnumerator) {
461+
count += 1;
462+
}
463+
});
461464
return count;
462465
}
463466

0 commit comments

Comments
 (0)