<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -223,6 +223,10 @@ typedef enum _ASINetworkErrorType {
 // Cancel loading and clean up
 - (void)cancelLoad;
 
+// Call to delete the temporary file used during a file download (if it exists)
+// No need to call this if the request succeeds - it is removed automatically
+- (void)removeTemporaryDownloadFile;
+
 #pragma mark upload/download progress
 
 // Called on main thread to update progress delegates</diff>
      <filename>Classes/ASIHTTPRequest.h</filename>
    </modified>
    <modified>
      <diff>@@ -458,6 +458,16 @@ static NSError *ASIUnableToCreateRequestError;
 }
 
 
+- (void)removeTemporaryDownloadFile
+{
+	//Remove the temporary file
+	NSError *removeError = nil;
+	[[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:&amp;removeError];
+	if (removeError) {
+		[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@&quot;Failed to delete file at %@ with error: %@&quot;,temporaryFileDownloadPath,removeError],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]];
+	}		
+}
+
 
 #pragma mark upload/download progress
 
@@ -1151,12 +1161,7 @@ static NSError *ASIUnableToCreateRequestError;
 				fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@&quot;Decompression of %@ failed with code %hi&quot;,temporaryFileDownloadPath,decompressionStatus],NSLocalizedDescriptionKey,nil]];
 			}
 				
-			//Remove the temporary file
-			NSError *removeError = nil;
-			[[NSFileManager defaultManager] removeItemAtPath:temporaryFileDownloadPath error:&amp;removeError];
-			if (removeError) {
-				fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@&quot;Failed to delete file at %@ with error: %@&quot;,temporaryFileDownloadPath,removeError],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]];
-			}			
+			[self removeTemporaryDownloadFile];
 		} else {
 					
 			//Remove any file at the destination path</diff>
      <filename>Classes/ASIHTTPRequest.m</filename>
    </modified>
    <modified>
      <diff>@@ -534,5 +534,4 @@
 	GHAssertTrue(success,@&quot;Failed to correctly display increment progress for a partial download&quot;);
 }
 
-
 @end</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.m</filename>
    </modified>
    <modified>
      <diff>@@ -192,7 +192,6 @@
 	[requestThatShouldFail release];	
 }
 
-
  
 - (void)requestFailedCancellingOthers:(ASIHTTPRequest *)request
 {
@@ -372,9 +371,42 @@
 	success = (progress == 1.0);
 	GHAssertTrue(success,@&quot;Failed to increment progress properly&quot;);
 	
-	[networkQueue release];
+	[networkQueue release];	
+	
+	
+	//Test the temporary file cleanup
+	complete = NO;
+	progress = 0;
+	networkQueue = [[ASINetworkQueue alloc] init];	
+	[networkQueue setDownloadProgressDelegate:self];
+	[networkQueue setShowAccurateProgress:YES];
+	[networkQueue setDelegate:self];
+	[networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];	
+	
+	request = [[[ASIHTTPRequest alloc] initWithURL:downloadURL] autorelease];
+	[request setDownloadDestinationPath:downloadPath];
+	[request setTemporaryFileDownloadPath:temporaryPath];
+	[request setAllowResumeForFileDownloads:YES];
+	[networkQueue addOperation:request];
+	[networkQueue go];
+	
+	// Let the download run for 5 seconds
+	timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(stopQueue:) userInfo:nil repeats:NO];
+	while (!complete) {
+		[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
+	}
+	[networkQueue cancelAllOperations];
+	
+	success = ([[NSFileManager defaultManager] fileExistsAtPath:temporaryPath]);
+	GHAssertTrue(success,@&quot;Temporary download file doesn't exist&quot;);	
+	
+	[request removeTemporaryDownloadFile];
+	
+	success = (![[NSFileManager defaultManager] fileExistsAtPath:temporaryPath]);
+	GHAssertTrue(success,@&quot;Temporary download file should have been deleted&quot;);		
 	
 	timeoutTimer = nil;
+	[networkQueue release];	
 	
 }
 </diff>
      <filename>Classes/Tests/ASINetworkQueueTests.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7a09218c4541df8e9b87fd8fbd99a90d46b0f66f</id>
    </parent>
  </parents>
  <author>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </author>
  <url>http://github.com/pokeb/asi-http-request/commit/83393425435ef4ea69498cbc71c217e797e760ca</url>
  <id>83393425435ef4ea69498cbc71c217e797e760ca</id>
  <committed-date>2009-03-22T09:41:36-07:00</committed-date>
  <authored-date>2009-03-22T09:41:36-07:00</authored-date>
  <message>Added method for cleaning up temporary file downloads, and tests for this</message>
  <tree>f79385626cf425a8f9de1d51ff05caaa0cf4ac0a</tree>
  <committer>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </committer>
</commit>
