From 71eefa47cf3708371f7489d7faecabf49b707c8b Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sun, 24 May 2020 00:00:35 +0200 Subject: [PATCH] Fix handling of UNC file URLs - Qt thinks UNC URLs should look like: file://1.2.3.4/share/file.img libcurl likes them: file:////1.2.3.4/share/file.img So correct that. - Mention it is an unspecified libcurl error if libcurl passes us an error code with an empty error message string. Closes #65 --- downloadthread.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/downloadthread.cpp b/downloadthread.cpp index ec5d101..2518a36 100644 --- a/downloadthread.cpp +++ b/downloadthread.cpp @@ -266,6 +266,14 @@ void DownloadThread::run() return; } + qDebug() << "Image URL:" << _url; + if (_url.startsWith("file://") && _url.at(7) != '/') + { + /* libcurl does not like UNC paths in the form of file://1.2.3.4/share */ + _url.replace("file://", "file:////"); + qDebug() << "Corrected UNC URL to:" << _url; + } + char errorBuf[CURL_ERROR_SIZE] = {0}; _c = curl_easy_init(); curl_easy_setopt(_c, CURLOPT_NOSIGNAL, 1); @@ -332,7 +340,10 @@ void DownloadThread::run() break; default: deleteDownloadedFile(); - _onDownloadError(errorBuf); + if (!errorBuf[0]) + _onDownloadError("Unspecified libcurl error"); + else + _onDownloadError(errorBuf); } }