mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-12 22:17:06 +00:00
cmFileCommand: Adopt file:// URL compatibility helper
Migrate the helper back from `cmCurl` because its only remaining functionality is specific to the `file(DOWNLOAD)` and `file(UPLOAD)` commands.
This commit is contained in:
@@ -227,20 +227,6 @@ std::string cmCurlSetNETRCOption(::CURL* curl, std::string const& netrc_level,
|
||||
return e;
|
||||
}
|
||||
|
||||
std::string cmCurlFixFileURL(std::string url)
|
||||
{
|
||||
if (!cmHasLiteralPrefix(url, "file://")) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// libcurl 7.77 and below accidentally allowed spaces in URLs in some cases.
|
||||
// One such case was file:// URLs, which CMake has long accepted as a result.
|
||||
// Explicitly encode spaces for a URL.
|
||||
cmSystemTools::ReplaceString(url, " ", "%20");
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
::CURL* cm_curl_easy_init()
|
||||
{
|
||||
::CURL* curl = curl_easy_init();
|
||||
|
||||
@@ -21,7 +21,6 @@ cm::optional<std::string> cmCurlPrintTLSVersion(int curl_tls_version);
|
||||
std::string cmCurlSetCAInfo(::CURL* curl, std::string const& cafile = {});
|
||||
std::string cmCurlSetNETRCOption(::CURL* curl, std::string const& netrc_level,
|
||||
std::string const& netrc_file);
|
||||
std::string cmCurlFixFileURL(std::string url);
|
||||
|
||||
::CURLcode cm_curl_global_init(long flags);
|
||||
::CURL* cm_curl_easy_init();
|
||||
|
||||
@@ -1698,6 +1698,16 @@ std::string const TLS_VERSION_DEFAULT = "1.2";
|
||||
// Stuff for curl download/upload
|
||||
using cmFileCommandVectorOfChar = std::vector<char>;
|
||||
|
||||
std::string CurlCompatFileURL(std::string url)
|
||||
{
|
||||
if (cmHasLiteralPrefix(url, "file://")) {
|
||||
// libcurl 7.77 and below accidentally allowed spaces in file:// URLs,
|
||||
// which CMake has long accepted as a result. Explicitly encode spaces.
|
||||
cmSystemTools::ReplaceString(url, " ", "%20");
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data)
|
||||
{
|
||||
int realsize = static_cast<int>(size * nmemb);
|
||||
@@ -2139,7 +2149,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
}
|
||||
|
||||
url = cmCurlFixFileURL(url);
|
||||
url = CurlCompatFileURL(url);
|
||||
|
||||
::CURL* curl;
|
||||
cm_curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
@@ -2541,7 +2551,7 @@ bool HandleUploadCommand(std::vector<std::string> const& args,
|
||||
|
||||
unsigned long file_size = cmsys::SystemTools::FileLength(filename);
|
||||
|
||||
url = cmCurlFixFileURL(url);
|
||||
url = CurlCompatFileURL(url);
|
||||
|
||||
::CURL* curl;
|
||||
cm_curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
Reference in New Issue
Block a user