Fixed #1422 - Added a fallback for #976 so that if there are images saved with the old format (no extension), they can still be loaded. Not the greatest way to fix it, but the simplest one.
This commit is contained in:
parent
9ecf488aff
commit
fca618fb61
|
@ -277,12 +277,25 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
// from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely.
|
// from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely.
|
||||||
exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]];
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
if (!exists) {
|
||||||
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
||||||
|
}
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
dispatch_async(_ioQueue, ^{
|
dispatch_async(_ioQueue, ^{
|
||||||
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
if (!exists) {
|
||||||
|
exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
||||||
|
}
|
||||||
|
|
||||||
if (completionBlock) {
|
if (completionBlock) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
completionBlock(exists);
|
completionBlock(exists);
|
||||||
|
@ -320,6 +333,13 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]];
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
NSArray *customPaths = [self.customPaths copy];
|
NSArray *customPaths = [self.customPaths copy];
|
||||||
for (NSString *path in customPaths) {
|
for (NSString *path in customPaths) {
|
||||||
NSString *filePath = [self cachePathForKey:key inPath:path];
|
NSString *filePath = [self cachePathForKey:key inPath:path];
|
||||||
|
@ -327,6 +347,13 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
if (imageData) {
|
if (imageData) {
|
||||||
return imageData;
|
return imageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
|
// checking the key with and without the extension
|
||||||
|
imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]];
|
||||||
|
if (imageData) {
|
||||||
|
return imageData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
|
|
Loading…
Reference in New Issue