mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
when downloading the blocklist, don't explicitly overwrite an existing file
This commit is contained in:
parent
ef2fd245cf
commit
efb5a070c9
2 changed files with 12 additions and 4 deletions
|
@ -39,6 +39,7 @@ typedef enum
|
|||
|
||||
BlocklistDownloaderViewController * fViewController;
|
||||
|
||||
NSString * fDestination;
|
||||
NSUInteger fCurrentSize;
|
||||
long long fExpectedSize;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#import "PrefsController.h"
|
||||
|
||||
#define LIST_URL @"http://update.transmissionbt.com/level1.gz"
|
||||
#define DESTINATION [NSTemporaryDirectory() stringByAppendingPathComponent: @"level1.gz"]
|
||||
#define FILE_NAME @"level1.gz"
|
||||
|
||||
@interface BlocklistDownloader (Private)
|
||||
|
||||
|
@ -79,6 +79,7 @@ BlocklistDownloader * fDownloader = nil;
|
|||
- (void) dealloc
|
||||
{
|
||||
[fDownload release];
|
||||
[fDestination release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -94,6 +95,11 @@ BlocklistDownloader * fDownloader = nil;
|
|||
[self release];
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *) download didCreateDestination: (NSString *) path
|
||||
{
|
||||
fDestination = [path retain];
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *) download didReceiveResponse: (NSURLResponse *) response
|
||||
{
|
||||
fState = BLOCKLIST_DL_DOWNLOADING;
|
||||
|
@ -139,7 +145,7 @@ BlocklistDownloader * fDownloader = nil;
|
|||
NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: LIST_URL]];
|
||||
|
||||
fDownload = [[NSURLDownload alloc] initWithRequest: request delegate: self];
|
||||
[fDownload setDestination: DESTINATION allowOverwrite: YES];
|
||||
[fDownload setDestination: [NSTemporaryDirectory() stringByAppendingPathComponent: FILE_NAME] allowOverwrite: NO];
|
||||
}
|
||||
|
||||
- (void) finishDownloadSuccess
|
||||
|
@ -149,10 +155,11 @@ BlocklistDownloader * fDownloader = nil;
|
|||
[fViewController setStatusProcessing];
|
||||
|
||||
//process data
|
||||
tr_blocklistSetContent([PrefsController handle], [DESTINATION UTF8String]);
|
||||
NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
|
||||
tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
|
||||
|
||||
//delete downloaded file
|
||||
[[NSFileManager defaultManager] removeItemAtPath: DESTINATION error: NULL];
|
||||
[[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
|
||||
|
||||
[fViewController setFinished];
|
||||
|
||||
|
|
Loading…
Reference in a new issue