From 06a387e4b2d778791c5b6725413653aae9fb096b Mon Sep 17 00:00:00 2001 From: Evadne Wu Date: Wed, 23 May 2012 17:29:07 +0800 Subject: [PATCH 1/2] fixes issues with nil path extension crashing applications --- IRRemoteResourceDownloadOperation.m | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/IRRemoteResourceDownloadOperation.m b/IRRemoteResourceDownloadOperation.m index 442a1da..4cccdf4 100644 --- a/IRRemoteResourceDownloadOperation.m +++ b/IRRemoteResourceDownloadOperation.m @@ -250,15 +250,20 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection { NSString *utiType = [(NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)self.mimeType, NULL) autorelease]; NSString *pathExtension = [(NSString *)UTTypeCopyPreferredTagWithClass((CFStringRef)utiType, kUTTagClassFilenameExtension) autorelease]; - NSString *fromPath = self.path; - NSString *toPath = [[self.path stringByDeletingPathExtension] stringByAppendingPathExtension:pathExtension]; - NSError *error = nil; - BOOL didMove = [fm moveItemAtPath:fromPath toPath:toPath error:&error]; - if (!didMove) { - NSLog(@"%s: %@ -> %@ Error: %@", __PRETTY_FUNCTION__, fromPath, toPath, error); - } else { - self.path = toPath; + if (pathExtension) { + + NSString *fromPath = self.path; + NSString *toPath = [[self.path stringByDeletingPathExtension] stringByAppendingPathExtension:pathExtension]; + NSError *error = nil; + + BOOL didMove = [fm moveItemAtPath:fromPath toPath:toPath error:&error]; + if (!didMove) { + NSLog(@"%s: %@ -> %@ Error: %@", __PRETTY_FUNCTION__, fromPath, toPath, error); + } else { + self.path = toPath; + } + } } From 6319a493a9b9d211864f13ff25bcac280a08e12d Mon Sep 17 00:00:00 2001 From: Evadne Wu Date: Fri, 25 May 2012 21:40:12 +0800 Subject: [PATCH 2/2] nils the file handle aggressively --- IRRemoteResourceDownloadOperation.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/IRRemoteResourceDownloadOperation.m b/IRRemoteResourceDownloadOperation.m index 4cccdf4..870781b 100644 --- a/IRRemoteResourceDownloadOperation.m +++ b/IRRemoteResourceDownloadOperation.m @@ -165,6 +165,7 @@ - (void) cancel { [self onOriginalQueue: ^ { [self.fileHandle closeFile]; + self.fileHandle = nil; }]; if (self.executing) { @@ -241,6 +242,7 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection { [self onOriginalQueue: ^ { [self.fileHandle closeFile]; + self.fileHandle = nil; if (self.mimeType) { @@ -285,6 +287,7 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er [self onOriginalQueue: ^ { [self.fileHandle closeFile]; + self.fileHandle = nil; [[NSFileManager defaultManager] removeItemAtPath:self.path error:nil];