Revision: 29550
http://sourceforge.net/p/bibdesk/svn/29550
Author: hofman
Date: 2025-09-08 08:58:23 +0000 (Mon, 08 Sep 2025)
Log Message:
-----------
remove allowOverwrite argument from destination delegate method for consistency
with other download classes, require target location not to exist.
Modified Paths:
--------------
trunk/bibdesk/BDSKDownloadManager.m
trunk/bibdesk/BDSKDownloader.h
trunk/bibdesk/BDSKDownloader.m
trunk/bibdesk/BDSKItemDownload.m
trunk/bibdesk/BDSKTextImportController.m
trunk/bibdesk/BDSKURLGroup.m
Modified: trunk/bibdesk/BDSKDownloadManager.m
===================================================================
--- trunk/bibdesk/BDSKDownloadManager.m 2025-09-07 22:25:44 UTC (rev 29549)
+++ trunk/bibdesk/BDSKDownloadManager.m 2025-09-08 08:58:23 UTC (rev 29550)
@@ -248,7 +248,14 @@
[sPanel setDirectoryURL:downloadsURL];
void (^handler)(NSModalResponse) = ^(NSModalResponse result){
- completionHandler(result == NSModalResponseOK ? [sPanel URL] : nil);
+ if (result == NSModalResponseOK) {
+ NSURL *fileURL = [sPanel URL];
+ if ([fileURL checkResourceIsReachableAndReturnError:NULL])
+ [[NSFileManager defaultManager] removeItemAtURL:fileURL
error:NULL];
+ completionHandler(fileURL);
+ } else {
+ completionHandler(nil);
+ }
};
if (window)
[sPanel beginSheetModalForWindow:window completionHandler:handler];
@@ -354,8 +361,6 @@
[downloadManager decideDestinationWithSuggestedFilename:filename
modalForWindow:nil completionHandler:^(NSURL *destination){
NSError *error = nil;
if (destination) {
- if ([destination checkResourceIsReachableAndReturnError:NULL])
- [[NSFileManager defaultManager] removeItemAtURL:destination
error:NULL];
if ([[NSFileManager defaultManager] moveItemAtURL:[webDownload
fileURL] toURL:destination error:&error])
[webDownload setFileURL:destination];
} else {
@@ -400,11 +405,8 @@
- (void)download:(WKDownload *)download
decideDestinationUsingResponse:(NSURLResponse *)response
suggestedFilename:(NSString *)filename completionHandler:(void (^)(NSURL *
destination))completionHandler API_AVAILABLE(macos(11.3)) {
[downloadManager decideDestinationWithSuggestedFilename:filename
modalForWindow:[[download webView] window] completionHandler:^(NSURL
*destination){
- if (destination) {
- if ([destination checkResourceIsReachableAndReturnError:NULL])
- [[NSFileManager defaultManager] removeItemAtURL:destination
error:NULL];
+ if (destination)
[[downloadManager webDownloadForDownload:download]
setFileURL:destination];
- }
completionHandler(destination);
}];
}
@@ -419,10 +421,8 @@
[downloadManager download:download didCompleteWithError:error];
}
-- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)filename
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler {
- [downloadManager decideDestinationWithSuggestedFilename:filename
modalForWindow:nil completionHandler:^(NSURL *destination){
- completionHandler(destination, YES);
- }];
+- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)filename
completionHandler:(void (^)(NSURL *destinationURL))completionHandler {
+ [downloadManager decideDestinationWithSuggestedFilename:filename
modalForWindow:nil completionHandler:completionHandler];
}
- (void)download:(BDSKDownload *)download didCreateDestination:(NSURL
*)locationURL {
Modified: trunk/bibdesk/BDSKDownloader.h
===================================================================
--- trunk/bibdesk/BDSKDownloader.h 2025-09-07 22:25:44 UTC (rev 29549)
+++ trunk/bibdesk/BDSKDownloader.h 2025-09-08 08:58:23 UTC (rev 29550)
@@ -97,7 +97,7 @@
- (NSWindow *)downloadWindowForAuthenticationSheet:(BDSKDownload *)download;
// only for file downloads
-- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *_Nullable destinationURL, BOOL
allowOverwrite))completionHandler;
+- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *_Nullable destinationURL))completionHandler;
- (void)download:(BDSKDownload *)download didCreateDestination:(NSURL
*)destinationURL;
@end
Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m 2025-09-07 22:25:44 UTC (rev 29549)
+++ trunk/bibdesk/BDSKDownloader.m 2025-09-08 08:58:23 UTC (rev 29550)
@@ -48,7 +48,7 @@
- (void)_didReceiveExpectedContentLength:(int64_t)expectedContentLength;
- (void)_didReceiveDataOfLength:(uint64_t)length;
- (void)_didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,
NSURLCredential *credential))completionHandler;
-- (void)_decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler;
+- (void)_decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL))completionHandler;
- (void)_didCreateDestination:(NSURL *)destinationURL;
@end
@@ -166,7 +166,7 @@
suggestedFileName = disposition;
}
- [download _decideDestinationWithSuggestedFilename:suggestedFileName
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
+ [download _decideDestinationWithSuggestedFilename:suggestedFileName
completionHandler:^(NSURL *destinationURL){
if (destinationURL == nil) {
NSError *error = [NSError errorWithDomain:NSURLErrorDomain
code:NSURLErrorCancelled userInfo:nil];
[download _didCompleteWithError:error];
@@ -174,13 +174,7 @@
} else {
NSError *error = nil;
NSFileManager *fm = [NSFileManager defaultManager];
- if ([destinationURL checkResourceIsReachableAndReturnError:NULL]) {
- if (allowOverwrite) {
- [fm removeItemAtURL:destinationURL error:NULL];
- } else {
- destinationURL = [fm uniqueFileURL:destinationURL];
- }
- } else if ([[destinationURL URLByDeletingLastPathComponent]
checkResourceIsReachableAndReturnError:NULL] == NO) {
+ if ([[destinationURL URLByDeletingLastPathComponent]
checkResourceIsReachableAndReturnError:NULL] == NO) {
[fm createDirectoryAtPath:[[destinationURL
URLByDeletingLastPathComponent] path] withIntermediateDirectories:YES
attributes:nil error:NULL];
}
if ([fm moveItemAtURL:location toURL:destinationURL error:&error])
{
@@ -304,12 +298,12 @@
}
}
-- (void)_decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler {
+- (void)_decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL))completionHandler {
if ([delegate
respondsToSelector:@selector(download:decideDestinationWithSuggestedFilename:completionHandler:)])
{
[delegate download:self
decideDestinationWithSuggestedFilename:suggestedFileName
completionHandler:completionHandler];
} else {
NSURL *destinationURL = [[NSFileManager defaultManager]
temporaryFileURLWithBasename:suggestedFileName];
- completionHandler(destinationURL, YES);
+ completionHandler(destinationURL);
}
}
Modified: trunk/bibdesk/BDSKItemDownload.m
===================================================================
--- trunk/bibdesk/BDSKItemDownload.m 2025-09-07 22:25:44 UTC (rev 29549)
+++ trunk/bibdesk/BDSKItemDownload.m 2025-09-08 08:58:23 UTC (rev 29550)
@@ -99,7 +99,7 @@
#pragma mark BDSKDownloadDelegate
-- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler {
+- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *destinationURL))completionHandler {
NSURL *destURL = nil;
NSString *extension = [destinationName pathExtension];
NSString *downloadsDirectory = [[[NSUserDefaults standardUserDefaults]
stringForKey:BDSKDownloadsDirectoryKey] stringByExpandingTildeInPath];
@@ -122,7 +122,9 @@
}
if (destURL == nil)
destURL = [NSURL fileURLWithPath:[NSTemporaryDirectory()
stringByAppendingPathComponent:destinationName]];
- completionHandler(destURL, NO);
+ if ([destURL checkResourceIsReachableAndReturnError:NULL])
+ destURL = [[NSFileManager defaultManager] uniqueFileURL:destURL];
+ completionHandler(destURL);
}
- (void)download:(BDSKDownload *)aDownload didCreateDestination:(NSURL
*)destinationURL {
Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m 2025-09-07 22:25:44 UTC (rev
29549)
+++ trunk/bibdesk/BDSKTextImportController.m 2025-09-08 08:58:23 UTC (rev
29550)
@@ -1217,7 +1217,7 @@
}
}
-- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *, BOOL))completionHandler {
+- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *))completionHandler {
NSString *extension = [destinationName pathExtension];
NSSavePanel *sPanel = [NSSavePanel savePanel];
@@ -1228,10 +1228,14 @@
[sPanel setNameFieldStringValue:destinationName];
[sPanel beginSheetModalForWindow:[self window]
completionHandler:^(NSModalResponse result){
- if (result == NSModalResponseOK)
- completionHandler([sPanel URL], YES);
- else
- completionHandler(nil, NO);
+ if (result == NSModalResponseOK) {
+ NSURL *fileURL = [sPanel URL];
+ if ([fileURL checkResourceIsReachableAndReturnError:NULL])
+ [[NSFileManager defaultManager] removeItemAtURL:fileURL
error:nil];
+ completionHandler(fileURL);
+ } else {
+ completionHandler(nil);
+ }
}];
}
Modified: trunk/bibdesk/BDSKURLGroup.m
===================================================================
--- trunk/bibdesk/BDSKURLGroup.m 2025-09-07 22:25:44 UTC (rev 29549)
+++ trunk/bibdesk/BDSKURLGroup.m 2025-09-08 08:58:23 UTC (rev 29550)
@@ -228,8 +228,8 @@
}
}
-- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *, BOOL))completionHandler {
- completionHandler([[NSFileManager defaultManager]
temporaryFileURLWithBasename:destinationName], YES);
+- (void)download:(BDSKDownload *)aDownload
decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *))completionHandler {
+ completionHandler([[NSFileManager defaultManager]
temporaryFileURLWithBasename:destinationName]);
}
- (void)download:(BDSKDownload *)aDownload didCreateDestination:(NSURL
*)destinationURL {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit