diff --git a/IRRemoteResourceDownloadOperation.m b/IRRemoteResourceDownloadOperation.m index 442a1da..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) { @@ -250,15 +252,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; + } + } } @@ -280,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];