Showing
6 changed files
with
54 additions
and
32 deletions
| @@ -135,8 +135,10 @@ | @@ -135,8 +135,10 @@ | ||
| 135 | 135 | ||
| 136 | + (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err | 136 | + (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err |
| 137 | { | 137 | { |
| 138 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 139 | + | ||
| 138 | // Create an empty file at the destination path | 140 | // Create an empty file at the destination path |
| 139 | - if (![[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { | 141 | + if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { |
| 140 | if (err) { | 142 | if (err) { |
| 141 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; | 143 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; |
| 142 | } | 144 | } |
| @@ -144,7 +146,7 @@ | @@ -144,7 +146,7 @@ | ||
| 144 | } | 146 | } |
| 145 | 147 | ||
| 146 | // Ensure the source file exists | 148 | // Ensure the source file exists |
| 147 | - if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath]) { | 149 | + if (![fileManager fileExistsAtPath:sourcePath]) { |
| 148 | if (err) { | 150 | if (err) { |
| 149 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; | 151 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; |
| 150 | } | 152 | } |
| @@ -133,8 +133,10 @@ | @@ -133,8 +133,10 @@ | ||
| 133 | 133 | ||
| 134 | + (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err | 134 | + (BOOL)uncompressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err |
| 135 | { | 135 | { |
| 136 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 137 | + | ||
| 136 | // Create an empty file at the destination path | 138 | // Create an empty file at the destination path |
| 137 | - if (![[NSFileManager defaultManager] createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { | 139 | + if (![fileManager createFileAtPath:destinationPath contents:[NSData data] attributes:nil]) { |
| 138 | if (err) { | 140 | if (err) { |
| 139 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; | 141 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed because we were to create a file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,nil]]; |
| 140 | } | 142 | } |
| @@ -142,7 +144,7 @@ | @@ -142,7 +144,7 @@ | ||
| 142 | } | 144 | } |
| 143 | 145 | ||
| 144 | // Ensure the source file exists | 146 | // Ensure the source file exists |
| 145 | - if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath]) { | 147 | + if (![fileManager fileExistsAtPath:sourcePath]) { |
| 146 | if (err) { | 148 | if (err) { |
| 147 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; | 149 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Decompression of %@ failed the file does not exist",sourcePath],NSLocalizedDescriptionKey,nil]]; |
| 148 | } | 150 | } |
| @@ -62,16 +62,19 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -62,16 +62,19 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 62 | [self clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy]; | 62 | [self clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy]; |
| 63 | [storagePath release]; | 63 | [storagePath release]; |
| 64 | storagePath = [path retain]; | 64 | storagePath = [path retain]; |
| 65 | + | ||
| 66 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 67 | + | ||
| 65 | BOOL isDirectory = NO; | 68 | BOOL isDirectory = NO; |
| 66 | NSArray *directories = [NSArray arrayWithObjects:path,[path stringByAppendingPathComponent:sessionCacheFolder],[path stringByAppendingPathComponent:permanentCacheFolder],nil]; | 69 | NSArray *directories = [NSArray arrayWithObjects:path,[path stringByAppendingPathComponent:sessionCacheFolder],[path stringByAppendingPathComponent:permanentCacheFolder],nil]; |
| 67 | for (NSString *directory in directories) { | 70 | for (NSString *directory in directories) { |
| 68 | - BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:directory isDirectory:&isDirectory]; | 71 | + BOOL exists = [fileManager fileExistsAtPath:directory isDirectory:&isDirectory]; |
| 69 | if (exists && !isDirectory) { | 72 | if (exists && !isDirectory) { |
| 70 | [[self accessLock] unlock]; | 73 | [[self accessLock] unlock]; |
| 71 | [NSException raise:@"FileExistsAtCachePath" format:@"Cannot create a directory for the cache at '%@', because a file already exists",directory]; | 74 | [NSException raise:@"FileExistsAtCachePath" format:@"Cannot create a directory for the cache at '%@', because a file already exists",directory]; |
| 72 | } else if (!exists) { | 75 | } else if (!exists) { |
| 73 | - [[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:NO attributes:nil error:nil]; | 76 | + [fileManager createDirectoryAtPath:directory withIntermediateDirectories:NO attributes:nil error:nil]; |
| 74 | - if (![[NSFileManager defaultManager] fileExistsAtPath:directory]) { | 77 | + if (![fileManager fileExistsAtPath:directory]) { |
| 75 | [[self accessLock] unlock]; | 78 | [[self accessLock] unlock]; |
| 76 | [NSException raise:@"FailedToCreateCacheDirectory" format:@"Failed to create a directory for the cache at '%@'",directory]; | 79 | [NSException raise:@"FailedToCreateCacheDirectory" format:@"Failed to create a directory for the cache at '%@'",directory]; |
| 77 | } | 80 | } |
| @@ -114,7 +117,7 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -114,7 +117,7 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 114 | [[request responseData] writeToFile:dataPath atomically:NO]; | 117 | [[request responseData] writeToFile:dataPath atomically:NO]; |
| 115 | } else if ([request downloadDestinationPath] && ![[request downloadDestinationPath] isEqualToString:dataPath]) { | 118 | } else if ([request downloadDestinationPath] && ![[request downloadDestinationPath] isEqualToString:dataPath]) { |
| 116 | NSError *error = nil; | 119 | NSError *error = nil; |
| 117 | - [[NSFileManager defaultManager] copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; | 120 | + [[[[NSFileManager alloc] init] autorelease] copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; |
| 118 | } | 121 | } |
| 119 | [[self accessLock] unlock]; | 122 | [[self accessLock] unlock]; |
| 120 | } | 123 | } |
| @@ -150,17 +153,19 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -150,17 +153,19 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 150 | extension = @"html"; | 153 | extension = @"html"; |
| 151 | } | 154 | } |
| 152 | 155 | ||
| 156 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 157 | + | ||
| 153 | // Look in the session store | 158 | // Look in the session store |
| 154 | NSString *path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder]; | 159 | NSString *path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder]; |
| 155 | NSString *dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:extension]]; | 160 | NSString *dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:extension]]; |
| 156 | - if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { | 161 | + if ([fileManager fileExistsAtPath:dataPath]) { |
| 157 | [[self accessLock] unlock]; | 162 | [[self accessLock] unlock]; |
| 158 | return dataPath; | 163 | return dataPath; |
| 159 | } | 164 | } |
| 160 | // Look in the permanent store | 165 | // Look in the permanent store |
| 161 | path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder]; | 166 | path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder]; |
| 162 | dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:extension]]; | 167 | dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:extension]]; |
| 163 | - if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { | 168 | + if ([fileManager fileExistsAtPath:dataPath]) { |
| 164 | [[self accessLock] unlock]; | 169 | [[self accessLock] unlock]; |
| 165 | return dataPath; | 170 | return dataPath; |
| 166 | } | 171 | } |
| @@ -175,17 +180,20 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -175,17 +180,20 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 175 | [[self accessLock] unlock]; | 180 | [[self accessLock] unlock]; |
| 176 | return nil; | 181 | return nil; |
| 177 | } | 182 | } |
| 183 | + | ||
| 184 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 185 | + | ||
| 178 | // Look in the session store | 186 | // Look in the session store |
| 179 | NSString *path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder]; | 187 | NSString *path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder]; |
| 180 | NSString *dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:@"cachedheaders"]]; | 188 | NSString *dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:@"cachedheaders"]]; |
| 181 | - if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { | 189 | + if ([fileManager fileExistsAtPath:dataPath]) { |
| 182 | [[self accessLock] unlock]; | 190 | [[self accessLock] unlock]; |
| 183 | return dataPath; | 191 | return dataPath; |
| 184 | } | 192 | } |
| 185 | // Look in the permanent store | 193 | // Look in the permanent store |
| 186 | path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder]; | 194 | path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder]; |
| 187 | dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:@"cachedheaders"]]; | 195 | dataPath = [path stringByAppendingPathComponent:[[[self class] keyForURL:url] stringByAppendingPathExtension:@"cachedheaders"]]; |
| 188 | - if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { | 196 | + if ([fileManager fileExistsAtPath:dataPath]) { |
| 189 | [[self accessLock] unlock]; | 197 | [[self accessLock] unlock]; |
| 190 | return dataPath; | 198 | return dataPath; |
| 191 | } | 199 | } |
| @@ -245,8 +253,10 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -245,8 +253,10 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 245 | [[self accessLock] unlock]; | 253 | [[self accessLock] unlock]; |
| 246 | return; | 254 | return; |
| 247 | } | 255 | } |
| 248 | - [[NSFileManager defaultManager] removeItemAtPath:cachedHeadersPath error:NULL]; | 256 | + |
| 249 | - [[NSFileManager defaultManager] removeItemAtPath:dataPath error:NULL]; | 257 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; |
| 258 | + [fileManager removeItemAtPath:cachedHeadersPath error:NULL]; | ||
| 259 | + [fileManager removeItemAtPath:dataPath error:NULL]; | ||
| 250 | [[self accessLock] unlock]; | 260 | [[self accessLock] unlock]; |
| 251 | } | 261 | } |
| 252 | 262 | ||
| @@ -355,14 +365,16 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -355,14 +365,16 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 355 | } | 365 | } |
| 356 | NSString *path = [[self storagePath] stringByAppendingPathComponent:(storagePolicy == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; | 366 | NSString *path = [[self storagePath] stringByAppendingPathComponent:(storagePolicy == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; |
| 357 | 367 | ||
| 368 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 369 | + | ||
| 358 | BOOL isDirectory = NO; | 370 | BOOL isDirectory = NO; |
| 359 | - BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]; | 371 | + BOOL exists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory]; |
| 360 | if (!exists || !isDirectory) { | 372 | if (!exists || !isDirectory) { |
| 361 | [[self accessLock] unlock]; | 373 | [[self accessLock] unlock]; |
| 362 | return; | 374 | return; |
| 363 | } | 375 | } |
| 364 | NSError *error = nil; | 376 | NSError *error = nil; |
| 365 | - NSArray *cacheFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error]; | 377 | + NSArray *cacheFiles = [fileManager contentsOfDirectoryAtPath:path error:&error]; |
| 366 | if (error) { | 378 | if (error) { |
| 367 | [[self accessLock] unlock]; | 379 | [[self accessLock] unlock]; |
| 368 | [NSException raise:@"FailedToTraverseCacheDirectory" format:@"Listing cache directory failed at path '%@'",path]; | 380 | [NSException raise:@"FailedToTraverseCacheDirectory" format:@"Listing cache directory failed at path '%@'",path]; |
| @@ -370,7 +382,7 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -370,7 +382,7 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 370 | for (NSString *file in cacheFiles) { | 382 | for (NSString *file in cacheFiles) { |
| 371 | NSString *extension = [file pathExtension]; | 383 | NSString *extension = [file pathExtension]; |
| 372 | if ([extension isEqualToString:@"cacheddata"] || [extension isEqualToString:@"cachedheaders"]) { | 384 | if ([extension isEqualToString:@"cacheddata"] || [extension isEqualToString:@"cachedheaders"]) { |
| 373 | - [[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:file] error:&error]; | 385 | + [fileManager removeItemAtPath:[path stringByAppendingPathComponent:file] error:&error]; |
| 374 | if (error) { | 386 | if (error) { |
| 375 | [[self accessLock] unlock]; | 387 | [[self accessLock] unlock]; |
| 376 | [NSException raise:@"FailedToRemoveCacheFile" format:@"Failed to remove cached data at path '%@'",path]; | 388 | [NSException raise:@"FailedToRemoveCacheFile" format:@"Failed to remove cached data at path '%@'",path]; |
| @@ -102,7 +102,7 @@ | @@ -102,7 +102,7 @@ | ||
| 102 | // If data is a path to a local file | 102 | // If data is a path to a local file |
| 103 | if ([data isKindOfClass:[NSString class]]) { | 103 | if ([data isKindOfClass:[NSString class]]) { |
| 104 | BOOL isDirectory = NO; | 104 | BOOL isDirectory = NO; |
| 105 | - BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:(NSString *)data isDirectory:&isDirectory]; | 105 | + BOOL fileExists = [[[[NSFileManager alloc] init] autorelease] fileExistsAtPath:(NSString *)data isDirectory:&isDirectory]; |
| 106 | if (!fileExists || isDirectory) { | 106 | if (!fileExists || isDirectory) { |
| 107 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"No file exists at %@",data],NSLocalizedDescriptionKey,nil]]]; | 107 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"No file exists at %@",data],NSLocalizedDescriptionKey,nil]]]; |
| 108 | } | 108 | } |
| @@ -316,7 +316,7 @@ | @@ -316,7 +316,7 @@ | ||
| 316 | - (void)appendPostDataFromFile:(NSString *)file | 316 | - (void)appendPostDataFromFile:(NSString *)file |
| 317 | { | 317 | { |
| 318 | NSError *err = nil; | 318 | NSError *err = nil; |
| 319 | - unsigned long long fileSize = [[[[NSFileManager defaultManager] attributesOfItemAtPath:file error:&err] objectForKey:NSFileSize] unsignedLongLongValue]; | 319 | + unsigned long long fileSize = [[[[[[NSFileManager alloc] init] autorelease] attributesOfItemAtPath:file error:&err] objectForKey:NSFileSize] unsignedLongLongValue]; |
| 320 | if (err) { | 320 | if (err) { |
| 321 | [self addToDebugBody:[NSString stringWithFormat:@"[Error: Failed to obtain the size of the file at '%@']",file]]; | 321 | [self addToDebugBody:[NSString stringWithFormat:@"[Error: Failed to obtain the size of the file at '%@']",file]]; |
| 322 | } else { | 322 | } else { |
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | #import "ASIDataCompressor.h" | 24 | #import "ASIDataCompressor.h" |
| 25 | 25 | ||
| 26 | // Automatically set on build | 26 | // Automatically set on build |
| 27 | -NSString *ASIHTTPRequestVersion = @"v1.8-10 2010-11-24"; | 27 | +NSString *ASIHTTPRequestVersion = @"v1.8-14 2010-12-02"; |
| 28 | 28 | ||
| 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 30 | 30 | ||
| @@ -497,7 +497,7 @@ static NSOperationQueue *sharedQueue = nil; | @@ -497,7 +497,7 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 497 | path = [self postBodyFilePath]; | 497 | path = [self postBodyFilePath]; |
| 498 | } | 498 | } |
| 499 | NSError *err = nil; | 499 | NSError *err = nil; |
| 500 | - [self setPostLength:[[[NSFileManager defaultManager] attributesOfItemAtPath:path error:&err] fileSize]]; | 500 | + [self setPostLength:[[[[[NSFileManager alloc] init] autorelease] attributesOfItemAtPath:path error:&err] fileSize]]; |
| 501 | if (err) { | 501 | if (err) { |
| 502 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",path],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; | 502 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",path],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; |
| 503 | return; | 503 | return; |
| @@ -1041,9 +1041,11 @@ static NSOperationQueue *sharedQueue = nil; | @@ -1041,9 +1041,11 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 1041 | 1041 | ||
| 1042 | - (void)updatePartialDownloadSize | 1042 | - (void)updatePartialDownloadSize |
| 1043 | { | 1043 | { |
| 1044 | - if ([self allowResumeForFileDownloads] && [self downloadDestinationPath] && [self temporaryFileDownloadPath] && [[NSFileManager defaultManager] fileExistsAtPath:[self temporaryFileDownloadPath]]) { | 1044 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; |
| 1045 | + | ||
| 1046 | + if ([self allowResumeForFileDownloads] && [self downloadDestinationPath] && [self temporaryFileDownloadPath] && [fileManager fileExistsAtPath:[self temporaryFileDownloadPath]]) { | ||
| 1045 | NSError *err = nil; | 1047 | NSError *err = nil; |
| 1046 | - [self setPartialDownloadSize:[[[NSFileManager defaultManager] attributesOfItemAtPath:[self temporaryFileDownloadPath] error:&err] fileSize]]; | 1048 | + [self setPartialDownloadSize:[[fileManager attributesOfItemAtPath:[self temporaryFileDownloadPath] error:&err] fileSize]]; |
| 1047 | if (err) { | 1049 | if (err) { |
| 1048 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",[self temporaryFileDownloadPath]],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; | 1050 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to get attributes for file at path '%@'",[self temporaryFileDownloadPath]],NSLocalizedDescriptionKey,error,NSUnderlyingErrorKey,nil]]]; |
| 1049 | return; | 1051 | return; |
| @@ -1084,14 +1086,16 @@ static NSOperationQueue *sharedQueue = nil; | @@ -1084,14 +1086,16 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 1084 | // | 1086 | // |
| 1085 | // Create the stream for the request | 1087 | // Create the stream for the request |
| 1086 | // | 1088 | // |
| 1087 | - | 1089 | + |
| 1090 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; | ||
| 1091 | + | ||
| 1088 | [self setReadStreamIsScheduled:NO]; | 1092 | [self setReadStreamIsScheduled:NO]; |
| 1089 | 1093 | ||
| 1090 | // Do we need to stream the request body from disk | 1094 | // Do we need to stream the request body from disk |
| 1091 | - if ([self shouldStreamPostDataFromDisk] && [self postBodyFilePath] && [[NSFileManager defaultManager] fileExistsAtPath:[self postBodyFilePath]]) { | 1095 | + if ([self shouldStreamPostDataFromDisk] && [self postBodyFilePath] && [fileManager fileExistsAtPath:[self postBodyFilePath]]) { |
| 1092 | 1096 | ||
| 1093 | // Are we gzipping the request body? | 1097 | // Are we gzipping the request body? |
| 1094 | - if ([self compressedPostBodyFilePath] && [[NSFileManager defaultManager] fileExistsAtPath:[self compressedPostBodyFilePath]]) { | 1098 | + if ([self compressedPostBodyFilePath] && [fileManager fileExistsAtPath:[self compressedPostBodyFilePath]]) { |
| 1095 | [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self compressedPostBodyFilePath] request:self]]; | 1099 | [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self compressedPostBodyFilePath] request:self]]; |
| 1096 | } else { | 1100 | } else { |
| 1097 | [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self postBodyFilePath] request:self]]; | 1101 | [self setPostBodyReadStream:[ASIInputStream inputStreamWithFileAtPath:[self postBodyFilePath] request:self]]; |
| @@ -3178,7 +3182,7 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3178,7 +3182,7 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3178 | // Response should already have been inflated, move the temporary file to the destination path | 3182 | // Response should already have been inflated, move the temporary file to the destination path |
| 3179 | } else { | 3183 | } else { |
| 3180 | NSError *moveError = nil; | 3184 | NSError *moveError = nil; |
| 3181 | - [[NSFileManager defaultManager] moveItemAtPath:[self temporaryUncompressedDataDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; | 3185 | + [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryUncompressedDataDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; |
| 3182 | if (moveError) { | 3186 | if (moveError) { |
| 3183 | fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; | 3187 | fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; |
| 3184 | } | 3188 | } |
| @@ -3198,7 +3202,7 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3198,7 +3202,7 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3198 | 3202 | ||
| 3199 | //Move the temporary file to the destination path | 3203 | //Move the temporary file to the destination path |
| 3200 | if (!fileError) { | 3204 | if (!fileError) { |
| 3201 | - [[NSFileManager defaultManager] moveItemAtPath:[self temporaryFileDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; | 3205 | + [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryFileDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; |
| 3202 | if (moveError) { | 3206 | if (moveError) { |
| 3203 | fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; | 3207 | fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]]; |
| 3204 | } | 3208 | } |
| @@ -3509,9 +3513,11 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3509,9 +3513,11 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3509 | 3513 | ||
| 3510 | + (BOOL)removeFileAtPath:(NSString *)path error:(NSError **)err | 3514 | + (BOOL)removeFileAtPath:(NSString *)path error:(NSError **)err |
| 3511 | { | 3515 | { |
| 3512 | - if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { | 3516 | + NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; |
| 3517 | + | ||
| 3518 | + if ([fileManager fileExistsAtPath:path]) { | ||
| 3513 | NSError *removeError = nil; | 3519 | NSError *removeError = nil; |
| 3514 | - [[NSFileManager defaultManager] removeItemAtPath:path error:&removeError]; | 3520 | + [fileManager removeItemAtPath:path error:&removeError]; |
| 3515 | if (removeError) { | 3521 | if (removeError) { |
| 3516 | if (err) { | 3522 | if (err) { |
| 3517 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",path],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]; | 3523 | *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to delete file at path '%@'",path],NSLocalizedDescriptionKey,removeError,NSUnderlyingErrorKey,nil]]; |
| @@ -3940,7 +3946,7 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3940,7 +3946,7 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3940 | 3946 | ||
| 3941 | + (NSString *)mimeTypeForFileAtPath:(NSString *)path | 3947 | + (NSString *)mimeTypeForFileAtPath:(NSString *)path |
| 3942 | { | 3948 | { |
| 3943 | - if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { | 3949 | + if (![[[[NSFileManager alloc] init] autorelease] fileExistsAtPath:path]) { |
| 3944 | return nil; | 3950 | return nil; |
| 3945 | } | 3951 | } |
| 3946 | // Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database | 3952 | // Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database |
| @@ -297,7 +297,7 @@ static NSMutableArray *requestsUsingXMLParser = nil; | @@ -297,7 +297,7 @@ static NSMutableArray *requestsUsingXMLParser = nil; | ||
| 297 | #if TARGET_OS_MAC && MAC_OS_X_VERSION_MAX_ALLOWED <= __MAC_10_5 | 297 | #if TARGET_OS_MAC && MAC_OS_X_VERSION_MAX_ALLOWED <= __MAC_10_5 |
| 298 | // xmlSaveToBuffer() is not implemented in the 10.5 version of libxml | 298 | // xmlSaveToBuffer() is not implemented in the 10.5 version of libxml |
| 299 | NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]; | 299 | NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]; |
| 300 | - [[NSFileManager defaultManager] createFileAtPath:tempPath contents:nil attributes:nil]; | 300 | + [[[[NSFileManager alloc] init] autorelease] createFileAtPath:tempPath contents:nil attributes:nil]; |
| 301 | saveContext = xmlSaveToFd([[NSFileHandle fileHandleForWritingAtPath:tempPath] fileDescriptor],NULL,2); // 2 == XML_SAVE_NO_DECL, this isn't declared on Mac OS 10.5 | 301 | saveContext = xmlSaveToFd([[NSFileHandle fileHandleForWritingAtPath:tempPath] fileDescriptor],NULL,2); // 2 == XML_SAVE_NO_DECL, this isn't declared on Mac OS 10.5 |
| 302 | xmlSaveDoc(saveContext, doc); | 302 | xmlSaveDoc(saveContext, doc); |
| 303 | xmlSaveClose(saveContext); | 303 | xmlSaveClose(saveContext); |
-
Please register or login to post a comment