Fail gracefully when attempting to download to an invalid local path
Showing
2 changed files
with
18 additions
and
1 deletions
@@ -2218,7 +2218,9 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; | @@ -2218,7 +2218,9 @@ static NSRecursiveLock *delegateAuthenticationLock = nil; | ||
2218 | + (int)uncompressZippedDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath | 2218 | + (int)uncompressZippedDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath |
2219 | { | 2219 | { |
2220 | // Create an empty file at the destination path | 2220 | // Create an empty file at the destination path |
2221 | - [[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]; | 2221 | + if (![[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { |
2222 | + return 1; | ||
2223 | + } | ||
2222 | 2224 | ||
2223 | // Get a FILE struct for the source file | 2225 | // Get a FILE struct for the source file |
2224 | NSFileHandle *inputFileHandle = [NSFileHandle fileHandleForReadingAtPath:sourcePath]; | 2226 | NSFileHandle *inputFileHandle = [NSFileHandle fileHandleForReadingAtPath:sourcePath]; |
@@ -879,6 +879,21 @@ | @@ -879,6 +879,21 @@ | ||
879 | GHAssertNotNil([request error],@"Failed to generate an authentication error"); | 879 | GHAssertNotNil([request error],@"Failed to generate an authentication error"); |
880 | } | 880 | } |
881 | 881 | ||
882 | +- (void)testFetchToInvalidPath | ||
883 | +{ | ||
884 | + // Test gzipped content | ||
885 | + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]]; | ||
886 | + [request setDownloadDestinationPath:@"/an/invalid/location.html"]; | ||
887 | + [request start]; | ||
888 | + GHAssertNotNil([request error],@"Failed to generate an authentication when attempting to write to an invalid location"); | ||
889 | + | ||
890 | + //Test non-gzipped content | ||
891 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/logo.png"]]; | ||
892 | + [request setDownloadDestinationPath:@"/an/invalid/location.png"]; | ||
893 | + [request start]; | ||
894 | + GHAssertNotNil([request error],@"Failed to generate an authentication when attempting to write to an invalid location"); | ||
895 | +} | ||
896 | + | ||
882 | @end | 897 | @end |
883 | 898 | ||
884 | 899 |
-
Please register or login to post a comment