Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding error handling when trying to unarchive an invalid archive.

  • Loading branch information...
commit 23b51d2c7705c38a05a52d5dc06a64df582c950a 1 parent 476065e
Tim Brückmann authored April 11, 2012

Showing 1 changed file with 17 additions and 6 deletions. Show diff stats Hide diff stats

  1. 23  SDURLCache.m
23  SDURLCache.m
@@ -700,12 +700,23 @@ - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request {
700 700
     dispatch_sync(get_disk_cache_queue(), ^{
701 701
         NSMutableDictionary *accesses = [self.diskCacheInfo objectForKey:kAFURLCacheInfoAccessesKey];
702 702
         if ([accesses objectForKey:cacheKey]) { // OPTI: Check for cache-hit in a in-memory dictionnary before to hit the FS
703  
-            response = [NSKeyedUnarchiver unarchiveObjectWithFile:[_diskCachePath stringByAppendingPathComponent:cacheKey]];
704  
-            if (response) {
705  
-                // OPTI: Log the entry last access time for LRU cache eviction algorithm but don't save the dictionary
706  
-                //       on disk now in order to save IO and time
707  
-                [accesses setObject:[NSDate date] forKey:cacheKey];
708  
-                _diskCacheInfoDirty = YES;
  703
+            @try {
  704
+                response = [NSKeyedUnarchiver unarchiveObjectWithFile:[_diskCachePath stringByAppendingPathComponent:cacheKey]];
  705
+                if (response) {
  706
+                    // OPTI: Log the entry last access time for LRU cache eviction algorithm but don't save the dictionary
  707
+                    //       on disk now in order to save IO and time
  708
+                    [accesses setObject:[NSDate date] forKey:cacheKey];
  709
+                    _diskCacheInfoDirty = YES;
  710
+                }
  711
+            }
  712
+            @catch (NSException *exception) {
  713
+                if ([exception.name isEqualToString:NSInvalidArgumentException]) {
  714
+                    NSLog(@"Could not unarchive object at %@, Invalid archive!", [_diskCachePath stringByAppendingPathComponent:cacheKey]);
  715
+                    [self removeCachedResponseForRequest:request];
  716
+                }
  717
+            }
  718
+            @finally {
  719
+                // do nothing
709 720
             }
710 721
         }
711 722
     });

0 notes on commit 23b51d2

Please sign in to comment.
Something went wrong with that request. Please try again.