diff options
author | Brad King <brad.king@kitware.com> | 2014-11-10 15:43:06 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-11-10 15:43:06 (GMT) |
commit | 742e6f8f06a635bbc0cb10a36ce68d5b9987f1f5 (patch) | |
tree | 1b112f40238dc7684d8c72a1c7a6b40284966008 | |
parent | 8532a4f9a061883dea639b2f7942c93a6682bc49 (diff) | |
parent | e63dcb1378bb6bd6b0a76c1760c4c24c27f221e5 (diff) | |
download | CMake-742e6f8f06a635bbc0cb10a36ce68d5b9987f1f5.zip CMake-742e6f8f06a635bbc0cb10a36ce68d5b9987f1f5.tar.gz CMake-742e6f8f06a635bbc0cb10a36ce68d5b9987f1f5.tar.bz2 |
Merge topic 'encoding-curl'
e63dcb13 Encoding: Use encoding libcurl expects with file: urls.
-rw-r--r-- | Source/cmFileCommand.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 7ebd750..b0ddff4 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -33,6 +33,7 @@ #include <cmsys/Glob.hxx> #include <cmsys/RegularExpression.hxx> #include <cmsys/FStream.hxx> +#include <cmsys/Encoding.hxx> // Table of permissions flags. #if defined(_WIN32) && !defined(__CYGWIN__) @@ -61,6 +62,35 @@ static mode_t mode_setuid = S_ISUID; static mode_t mode_setgid = S_ISGID; #endif +#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8) +// libcurl doesn't support file:// urls for unicode filenames on Windows. +// Convert string from UTF-8 to ACP if this is a file:// URL. +static std::string fix_file_url_windows(const std::string& url) +{ + std::string ret = url; + if(strncmp(url.c_str(), "file://", 7) == 0) + { + cmsys_stl::wstring wurl = cmsys::Encoding::ToWide(url); + if(!wurl.empty()) + { + int mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, + NULL, 0, NULL, NULL); + if(mblen > 0) + { + std::vector<char> chars(mblen); + mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, + &chars[0], mblen, NULL, NULL); + if(mblen > 0) + { + ret = &chars[0]; + } + } + } + } + return ret; +} +#endif + // cmLibraryCommand bool cmFileCommand ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) @@ -2988,6 +3018,10 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) return false; } +#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8) + url = fix_file_url_windows(url); +#endif + ::CURL *curl; ::curl_global_init(CURL_GLOBAL_DEFAULT); curl = ::curl_easy_init(); @@ -3250,6 +3284,10 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) unsigned long file_size = cmsys::SystemTools::FileLength(filename.c_str()); +#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8) + url = fix_file_url_windows(url); +#endif + ::CURL *curl; ::curl_global_init(CURL_GLOBAL_DEFAULT); curl = ::curl_easy_init(); |