Cache would not store the downloaded data if the cached file already existed. Remove old one first
Showing
1 changed file
with
7 additions
and
2 deletions
@@ -183,9 +183,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -183,9 +183,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
183 | 183 | ||
184 | if ([request responseData]) { | 184 | if ([request responseData]) { |
185 | [[request responseData] writeToFile:dataPath atomically:NO]; | 185 | [[request responseData] writeToFile:dataPath atomically:NO]; |
186 | - } else if ([request downloadDestinationPath] && ![[request downloadDestinationPath] isEqualToString:dataPath]) { | 186 | + } else if ([request downloadDestinationPath] && ![[request downloadDestinationPath] isEqualToString:dataPath]) { |
187 | NSError *error = nil; | 187 | NSError *error = nil; |
188 | - [[[[NSFileManager alloc] init] autorelease] copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; | 188 | + NSFileManager* manager = [[NSFileManager alloc] init]; |
189 | + if ([manager fileExistsAtPath:dataPath]) { | ||
190 | + [manager removeItemAtPath:dataPath error:&error]; | ||
191 | + } | ||
192 | + [manager copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; | ||
193 | + [manager release]; | ||
189 | } | 194 | } |
190 | [[self accessLock] unlock]; | 195 | [[self accessLock] unlock]; |
191 | } | 196 | } |
-
Please register or login to post a comment