From 03b97e24f4e036e73ef7340bc5208ba9204a9fe4 Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Fri, 12 Dec 2003 23:00:58 +0000 Subject: [PATCH] Fix problem with downloads to helper apps creating "stuck" downloads in "Starting..." state. --- .../downloads/src/nsDownloadManager.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index 6186a7712c9..b9451608c42 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -491,7 +491,31 @@ nsDownloadManager::AddDownload(DownloadType aDownloadType, internalDownload->SetTarget(aTarget); internalDownload->SetSource(aSource); - // the persistent descriptor of the target is the unique identifier we use + // The path is the uniquifier of the download resource. + // XXXben - this is a little risky - really we should be using anonymous + // resources because of duplicate file paths on MacOSX. We can't use persistent + // descriptor here because in most cases the file doesn't exist on the local disk + // yet (it's being downloaded) and persistentDescriptor fails on MacOSX for + // non-existent files. + + // XXXben - This is not really ideal. If the download is to be handled by a + // helper application, then we want to see if there is a duplicate file + // in place in the temp folder and remove it _NOW_ before the External + // Helper App Service gets a chance to make a unique clone. If we don't, + // the EHAS will create a unique version of the name which will muck + // with our RDF datasource. We can't create a unique name here either, + // because the EHAS isn't smart enough to know that we're fooling with + // it... + nsMIMEInfoHandleAction action = nsIMIMEInfo::saveToDisk; + aMIMEInfo->GetPreferredAction(&action); + if (action == nsIMIMEInfo::useHelperApp || + action == nsIMIMEInfo::useSystemDefault) { + PRBool fileExists; + aTarget->Exists(&fileExists); + if (fileExists) + aTarget->Remove(PR_TRUE); + } + nsAutoString path; rv = aTarget->GetPath(path); if (NS_FAILED(rv)) return rv;