Skip to content
Permalink
Browse files
[Curl] Delete temporally downloaded file when it cancelled
https://bugs.webkit.org/show_bug.cgi?id=134393

Patch by Basuke Suzuki <Basuke.Suzuki@sony.com> on 2017-10-25
Reviewed by Alex Christensen.

* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::didCancelTransfer):
(WebCore::CurlRequest::writeDataToDownloadFileIfEnabled):
(WebCore::CurlRequest::closeDownloadFile):
(WebCore::CurlRequest::cleanupDownloadFile):
* platform/network/curl/CurlRequest.h:

Canonical link: https://commits.webkit.org/194989@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223995 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
basuke authored and webkit-commit-queue committed Oct 25, 2017
1 parent 48f6a32 commit bf4ad3544371a60e973ef962f2c2b1e5d3f09f88
Showing 3 changed files with 34 additions and 6 deletions.
@@ -1,3 +1,17 @@
2017-10-25 Basuke Suzuki <Basuke.Suzuki@sony.com>

[Curl] Delete temporally downloaded file when it cancelled
https://bugs.webkit.org/show_bug.cgi?id=134393

Reviewed by Alex Christensen.

* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::didCancelTransfer):
(WebCore::CurlRequest::writeDataToDownloadFileIfEnabled):
(WebCore::CurlRequest::closeDownloadFile):
(WebCore::CurlRequest::cleanupDownloadFile):
* platform/network/curl/CurlRequest.h:

2017-10-25 Youenn Fablet <youenn@apple.com>

Add service worker handle fetch support for all subresource requests
@@ -377,6 +377,7 @@ void CurlRequest::didCompleteTransfer(CURLcode result)
void CurlRequest::didCancelTransfer()
{
finalizeTransfer();
cleanupDownloadFile();
}

void CurlRequest::finalizeTransfer()
@@ -610,13 +611,15 @@ const String& CurlRequest::getDownloadedFilePath()

void CurlRequest::writeDataToDownloadFileIfEnabled(const SharedBuffer& buffer)
{
LockHolder locker(m_downloadMutex);
{
LockHolder locker(m_downloadMutex);

if (!m_isEnabledDownloadToFile)
return;
if (!m_isEnabledDownloadToFile)
return;

if (m_downloadFilePath.isEmpty())
m_downloadFilePath = openTemporaryFile("download", m_downloadFileHandle);
if (m_downloadFilePath.isEmpty())
m_downloadFilePath = openTemporaryFile("download", m_downloadFileHandle);
}

if (m_downloadFileHandle != invalidPlatformFileHandle)
writeToFile(m_downloadFileHandle, buffer.data(), buffer.size());
@@ -629,10 +632,20 @@ void CurlRequest::closeDownloadFile()
if (m_downloadFileHandle == invalidPlatformFileHandle)
return;

WebCore::closeFile(m_downloadFileHandle);
closeFile(m_downloadFileHandle);
m_downloadFileHandle = invalidPlatformFileHandle;
}

void CurlRequest::cleanupDownloadFile()
{
LockHolder locker(m_downloadMutex);

if (!m_downloadFilePath.isEmpty()) {
deleteFile(m_downloadFilePath);
m_downloadFilePath = String();
}
}

CURLcode CurlRequest::willSetupSslCtxCallback(CURL*, void* sslCtx, void* userData)
{
return static_cast<CurlRequest*>(userData)->willSetupSslCtx(sslCtx);
@@ -117,6 +117,7 @@ class CurlRequest : public ThreadSafeRefCounted<CurlRequest>, public CurlJobClie
// Download
void writeDataToDownloadFileIfEnabled(const SharedBuffer&);
void closeDownloadFile();
void cleanupDownloadFile();

// Callback functions for curl
static CURLcode willSetupSslCtxCallback(CURL*, void*, void*);

0 comments on commit bf4ad35

Please sign in to comment.