Skip to content

Commit

Permalink
Check fileURL outside of the locked scope (#262)
Browse files Browse the repository at this point in the history
We can exit immediately when fileURL is invalid without acquiring and
then releasing the write lock.
  • Loading branch information
jparise authored Mar 2, 2020
1 parent 91fd8d0 commit b32bd0a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Source/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,13 @@ - (BOOL)_locked_setAgeLimit:(NSTimeInterval)ageLimit forURL:(NSURL *)fileURL
- (BOOL)removeFileAndExecuteBlocksForKey:(NSString *)key
{
NSURL *fileURL = [self encodedFileURLForKey:key];

if (!fileURL) {
return NO;
}

// We only need to lock until writable at the top because once writable, always writable
[self lockForWriting];
if (!fileURL || ![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
[self unlock];
return NO;
}
Expand Down

0 comments on commit b32bd0a

Please sign in to comment.