diff --git a/Downloader.m b/Downloader.m index c0771dc..9ae7215 100644 --- a/Downloader.m +++ b/Downloader.m @@ -29,7 +29,9 @@ NSURL* url = [NSURL URLWithString:_params.fromUrl]; - [[NSFileManager defaultManager] createFileAtPath:_params.toFile contents:nil attributes:nil]; + if (![[NSFileManager defaultManager] fileExistsAtPath:_params.toFile]) { + [[NSFileManager defaultManager] createFileAtPath:_params.toFile contents:nil attributes:nil]; + } _fileHandle = [NSFileHandle fileHandleForWritingAtPath:_params.toFile]; if (!_fileHandle) { @@ -97,8 +99,10 @@ NSURL *destURL = [NSURL fileURLWithPath:_params.toFile]; NSFileManager *fm = [NSFileManager defaultManager]; NSError *error = nil; - [fm removeItemAtURL:destURL error:nil]; // Remove file at destination path, if it exists - [fm moveItemAtURL:location toURL:destURL error:&error]; + if([_statusCode integerValue] >= 200 && [_statusCode integerValue] < 300) { + [fm removeItemAtURL:destURL error:nil]; // Remove file at destination path, if it exists + [fm moveItemAtURL:location toURL:destURL error:&error]; + } if (error) { NSLog(@"RNFS download: unable to move tempfile to destination. %@, %@", error, error.userInfo); }