[SOUP] WebKitDownload cannot overwrite existing file
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Sep 2014 08:35:52 +0000 (08:35 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Sep 2014 08:35:52 +0000 (08:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136322

Patch by Michael Catanzaro <mcatanzaro@igalia.com> on 2014-09-01
Reviewed by Carlos Garcia Campos.

* Shared/Downloads/soup/DownloadSoup.cpp:
(WebKit::DownloadClient::didReceiveResponse): pass a member variable
to Download::decideDestinationWithSuggestedFilename instead of a
temporary bool, so we can use the result in didFinishLoading.
(WebKit::DownloadClient::didFinishLoading): overwrite the destination
if Download::decideDestinationWithSuggestedFilename determined we
should do so.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173154 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp

index 8bcfb49..86727c4 100644 (file)
@@ -1,3 +1,18 @@
+2014-09-01  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [SOUP] WebKitDownload cannot overwrite existing file
+        https://bugs.webkit.org/show_bug.cgi?id=136322
+
+        Reviewed by Carlos Garcia Campos.
+
+        * Shared/Downloads/soup/DownloadSoup.cpp:
+        (WebKit::DownloadClient::didReceiveResponse): pass a member variable
+        to Download::decideDestinationWithSuggestedFilename instead of a
+        temporary bool, so we can use the result in didFinishLoading.
+        (WebKit::DownloadClient::didFinishLoading): overwrite the destination
+        if Download::decideDestinationWithSuggestedFilename determined we
+        should do so.
+
 2014-08-31  Tim Horton  <timothy_horton@apple.com>
 
         Occasional crashes (null deref) under ViewGestureController::endMagnificationGesture
index abecf25..8363865 100644 (file)
@@ -50,6 +50,7 @@ class DownloadClient : public ResourceHandleClient {
 public:
     DownloadClient(Download* download)
         : m_download(download)
+        , m_allowOverwrite(false)
     {
     }
 
@@ -88,8 +89,7 @@ public:
             suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent());
         }
 
-        bool overwrite;
-        m_destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, overwrite);
+        m_destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, m_allowOverwrite);
         if (m_destinationURI.isEmpty()) {
 #if PLATFORM(GTK)
             GUniquePtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data()));
@@ -137,7 +137,7 @@ public:
         ASSERT(m_intermediateFile);
         GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_uri(m_destinationURI.utf8().data()));
         GUniqueOutPtr<GError> error;
-        if (!g_file_move(m_intermediateFile.get(), destinationFile.get(), G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error.outPtr())) {
+        if (!g_file_move(m_intermediateFile.get(), destinationFile.get(), m_allowOverwrite ? G_FILE_COPY_OVERWRITE : G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error.outPtr())) {
             downloadFailed(platformDownloadDestinationError(m_response, error->message));
             return;
         }
@@ -197,6 +197,7 @@ public:
     GRefPtr<GFile> m_intermediateFile;
     ResourceResponse m_delayedResponse;
     GMainLoopSource m_handleResponseLater;
+    bool m_allowOverwrite;
 };
 
 void Download::start()