diff options
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 331 |
1 files changed, 186 insertions, 145 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 5777fb2..88185bd 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -10,6 +10,7 @@ #include "cmsys/String.hxx" #include <algorithm> #include <assert.h> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -19,6 +20,7 @@ #include "cmAlgorithms.h" #include "cmCommandArgumentsHelper.h" #include "cmCryptoHash.h" +#include "cmFSPermissions.h" #include "cmFileLockPool.h" #include "cmFileTimeComparison.h" #include "cmGeneratorExpression.h" @@ -30,7 +32,6 @@ #include "cmPolicies.h" #include "cmSystemTools.h" #include "cmTimestamp.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" #include "cmake.h" @@ -50,32 +51,7 @@ class cmSystemToolsFileTime; -// Table of permissions flags. -#if defined(_WIN32) && !defined(__CYGWIN__) -static mode_t mode_owner_read = S_IREAD; -static mode_t mode_owner_write = S_IWRITE; -static mode_t mode_owner_execute = S_IEXEC; -static mode_t mode_group_read = 0; -static mode_t mode_group_write = 0; -static mode_t mode_group_execute = 0; -static mode_t mode_world_read = 0; -static mode_t mode_world_write = 0; -static mode_t mode_world_execute = 0; -static mode_t mode_setuid = 0; -static mode_t mode_setgid = 0; -#else -static mode_t mode_owner_read = S_IRUSR; -static mode_t mode_owner_write = S_IWUSR; -static mode_t mode_owner_execute = S_IXUSR; -static mode_t mode_group_read = S_IRGRP; -static mode_t mode_group_write = S_IWGRP; -static mode_t mode_group_execute = S_IXGRP; -static mode_t mode_world_read = S_IROTH; -static mode_t mode_world_write = S_IWOTH; -static mode_t mode_world_execute = S_IXOTH; -static mode_t mode_setuid = S_ISUID; -static mode_t mode_setgid = S_ISGID; -#endif +using namespace cmFSPermissions; #if defined(_WIN32) // libcurl doesn't support file:// urls for unicode filenames on Windows. @@ -269,17 +245,17 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args) cmCommandArgumentGroup group; cmCAString readArg(&argHelper, "READ"); - cmCAString fileNameArg(&argHelper, CM_NULLPTR); - cmCAString resultArg(&argHelper, CM_NULLPTR); + cmCAString fileNameArg(&argHelper, nullptr); + cmCAString resultArg(&argHelper, nullptr); cmCAString offsetArg(&argHelper, "OFFSET", &group); cmCAString limitArg(&argHelper, "LIMIT", &group); cmCAEnabler hexOutputArg(&argHelper, "HEX", &group); - readArg.Follows(CM_NULLPTR); + readArg.Follows(nullptr); fileNameArg.Follows(&readArg); resultArg.Follows(&fileNameArg); group.Follows(&resultArg); - argHelper.Parse(&args, CM_NULLPTR); + argHelper.Parse(&args, nullptr); std::string fileName = fileNameArg.GetString(); if (!cmsys::SystemTools::FileIsFullPath(fileName.c_str())) { @@ -368,8 +344,8 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args) return false; } - CM_AUTO_PTR<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); - if (hash.get()) { + std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); + if (hash) { std::string out = hash->HashFile(args[1]); if (!out.empty()) { this->Makefile->AddDefinition(args[2], out.c_str()); @@ -656,7 +632,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) c = current_str[current_str.size() - 1 - j]; fin.putback(static_cast<char>(c)); } - current_str = ""; + current_str.clear(); } } @@ -667,14 +643,14 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { - s = ""; + s.clear(); break; } strings.push_back(s); } // Reset the string to empty. - s = ""; + s.clear(); } else if (current_str.empty()) { // A non-string character has been found. Check if the current // string matches the requirements. We require that the length @@ -683,14 +659,14 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) (!have_regex || regex.find(s.c_str()))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { - s = ""; + s.clear(); break; } strings.push_back(s); } // Reset the string to empty. - s = ""; + s.clear(); } else { s += current_str; } @@ -700,12 +676,12 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { - s = ""; + s.clear(); break; } strings.push_back(s); } - s = ""; + s.clear(); } } @@ -723,20 +699,18 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) // Encode the result in a CMake list. const char* sep = ""; std::string output; - for (std::vector<std::string>::const_iterator si = strings.begin(); - si != strings.end(); ++si) { + for (std::string const& sr : strings) { // Separate the strings in the output to make it a list. output += sep; sep = ";"; // Store the string in the output, but escape semicolons to // make sure it is a list. - std::string const& sr = *si; - for (unsigned int i = 0; i < sr.size(); ++i) { - if (sr[i] == ';') { + for (char i : sr) { + if (i == ';') { output += '\\'; } - output += sr[i]; + output += i; } } @@ -841,17 +815,16 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, if (!globMessages.empty()) { bool shouldExit = false; - for (cmsys::Glob::GlobMessagesIterator it = globMessages.begin(); - it != globMessages.end(); ++it) { - if (it->type == cmsys::Glob::cyclicRecursion) { + for (cmsys::Glob::Message const& globMessage : globMessages) { + if (globMessage.type == cmsys::Glob::cyclicRecursion) { this->Makefile->IssueMessage( cmake::AUTHOR_WARNING, "Cyclic recursion detected while globbing for '" + *i + "':\n" + - it->content); + globMessage.content); } else { this->Makefile->IssueMessage( cmake::FATAL_ERROR, "Error has occurred while globbing for '" + - *i + "' - " + it->content); + *i + "' - " + globMessage.content); shouldExit = true; } } @@ -940,9 +913,9 @@ bool cmFileCommand::HandleDifferentCommand( */ // Evaluate arguments. - const char* file_lhs = CM_NULLPTR; - const char* file_rhs = CM_NULLPTR; - const char* var = CM_NULLPTR; + const char* file_lhs = nullptr; + const char* file_rhs = nullptr; + const char* var = nullptr; enum Doing { DoingNone, @@ -997,7 +970,7 @@ struct cmFileCopier , MatchlessFiles(true) , FilePermissions(0) , DirPermissions(0) - , CurrentMatchRule(CM_NULLPTR) + , CurrentMatchRule(nullptr) , UseGivenPermissionsFile(false) , UseGivenPermissionsDir(false) , UseSourcePermissions(true) @@ -1060,12 +1033,11 @@ protected: // Collect properties from all matching rules. bool matched = false; MatchProperties result; - for (std::vector<MatchRule>::iterator mr = this->MatchRules.begin(); - mr != this->MatchRules.end(); ++mr) { - if (mr->Regex.find(file_to_match)) { + for (MatchRule& mr : this->MatchRules) { + if (mr.Regex.find(file_to_match)) { matched = true; - result.Exclude |= mr->Properties.Exclude; - result.Permissions |= mr->Properties.Permissions; + result.Exclude |= mr.Properties.Exclude; + result.Permissions |= mr.Properties.Permissions; } } if (!matched && !this->MatchlessFiles) { @@ -1076,11 +1048,26 @@ protected: bool SetPermissions(const char* toFile, mode_t permissions) { - if (permissions && !cmSystemTools::SetPermissions(toFile, permissions)) { - std::ostringstream e; - e << this->Name << " cannot set permissions on \"" << toFile << "\""; - this->FileCommand->SetError(e.str()); - return false; + if (permissions) { +#ifdef WIN32 + if (Makefile->IsOn("CMAKE_CROSSCOMPILING")) { + std::string mode_t_adt_filename = + std::string(toFile) + ":cmake_mode_t"; + + cmsys::ofstream permissionStream(mode_t_adt_filename.c_str()); + + if (permissionStream) { + permissionStream << std::oct << permissions << std::endl; + } + } +#endif + + if (!cmSystemTools::SetPermissions(toFile, permissions)) { + std::ostringstream e; + e << this->Name << " cannot set permissions on \"" << toFile << "\""; + this->FileCommand->SetError(e.str()); + return false; + } } return true; } @@ -1088,29 +1075,7 @@ protected: // Translate an argument to a permissions bit. bool CheckPermissions(std::string const& arg, mode_t& permissions) { - if (arg == "OWNER_READ") { - permissions |= mode_owner_read; - } else if (arg == "OWNER_WRITE") { - permissions |= mode_owner_write; - } else if (arg == "OWNER_EXECUTE") { - permissions |= mode_owner_execute; - } else if (arg == "GROUP_READ") { - permissions |= mode_group_read; - } else if (arg == "GROUP_WRITE") { - permissions |= mode_group_write; - } else if (arg == "GROUP_EXECUTE") { - permissions |= mode_group_execute; - } else if (arg == "WORLD_READ") { - permissions |= mode_world_read; - } else if (arg == "WORLD_WRITE") { - permissions |= mode_world_write; - } else if (arg == "WORLD_EXECUTE") { - permissions |= mode_world_execute; - } else if (arg == "SETUID") { - permissions |= mode_setuid; - } else if (arg == "SETGID") { - permissions |= mode_setgid; - } else { + if (!cmFSPermissions::stringToModeT(arg, permissions)) { std::ostringstream e; e << this->Name << " given invalid permission \"" << arg << "\"."; this->FileCommand->SetError(e.str()); @@ -1406,23 +1371,22 @@ bool cmFileCopier::Run(std::vector<std::string> const& args) return false; } - for (std::vector<std::string>::const_iterator i = this->Files.begin(); - i != this->Files.end(); ++i) { + for (std::string const& f : this->Files) { std::string file; - if (!i->empty() && !cmSystemTools::FileIsFullPath(*i)) { + if (!f.empty() && !cmSystemTools::FileIsFullPath(f)) { if (!this->FilesFromDir.empty()) { file = this->FilesFromDir; } else { file = this->Makefile->GetCurrentSourceDirectory(); } file += "/"; - file += *i; + file += f; } else if (!this->FilesFromDir.empty()) { this->FileCommand->SetError("option FILES_FROM_DIR requires all files " "to be specified as relative paths."); return false; } else { - file = *i; + file = f; } // Split the input file into its directory and name components. @@ -1435,7 +1399,7 @@ bool cmFileCopier::Run(std::vector<std::string> const& args) // Compute the full path to the destination file. std::string toFile = this->Destination; if (!this->FilesFromDir.empty()) { - std::string dir = cmSystemTools::GetFilenamePath(*i); + std::string dir = cmSystemTools::GetFilenamePath(f); if (!dir.empty()) { toFile += "/"; toFile += dir; @@ -1696,7 +1660,7 @@ struct cmFileInstaller : public cmFileCopier this->Manifest = this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES"); } - ~cmFileInstaller() CM_OVERRIDE + ~cmFileInstaller() override { // Save the updated install manifest. this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES", @@ -1721,12 +1685,12 @@ protected: this->Manifest += file.substr(this->DestDirLength); } - std::string const& ToName(std::string const& fromName) CM_OVERRIDE + std::string const& ToName(std::string const& fromName) override { return this->Rename.empty() ? fromName : this->Rename; } - void ReportCopy(const char* toFile, Type type, bool copy) CM_OVERRIDE + void ReportCopy(const char* toFile, Type type, bool copy) override { if (!this->MessageNever && (copy || !this->MessageLazy)) { std::string message = (copy ? "Installing: " : "Up-to-date: "); @@ -1738,11 +1702,11 @@ protected: this->ManifestAppend(toFile); } } - bool ReportMissing(const char* fromFile) CM_OVERRIDE + bool ReportMissing(const char* fromFile) override { return (this->Optional || this->cmFileCopier::ReportMissing(fromFile)); } - bool Install(const char* fromFile, const char* toFile) CM_OVERRIDE + bool Install(const char* fromFile, const char* toFile) override { // Support installing from empty source to make a directory. if (this->InstallType == cmInstallType_DIRECTORY && !*fromFile) { @@ -1751,16 +1715,16 @@ protected: return this->cmFileCopier::Install(fromFile, toFile); } - bool Parse(std::vector<std::string> const& args) CM_OVERRIDE; + bool Parse(std::vector<std::string> const& args) override; enum { DoingType = DoingLast1, DoingRename, DoingLast2 }; - bool CheckKeyword(std::string const& arg) CM_OVERRIDE; - bool CheckValue(std::string const& arg) CM_OVERRIDE; - void DefaultFilePermissions() CM_OVERRIDE + bool CheckKeyword(std::string const& arg) override; + bool CheckValue(std::string const& arg) override; + void DefaultFilePermissions() override { this->cmFileCopier::DefaultFilePermissions(); // Add execute permissions based on the target type. @@ -2005,9 +1969,30 @@ bool cmFileInstaller::HandleInstallDestination() this->DestDirLength = int(sdestdir.size()); } + // check if default dir creation permissions were set + mode_t default_dir_mode_v = 0; + mode_t* default_dir_mode = nullptr; + const char* default_dir_install_permissions = this->Makefile->GetDefinition( + "CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS"); + if (default_dir_install_permissions && *default_dir_install_permissions) { + std::vector<std::string> items; + cmSystemTools::ExpandListArgument(default_dir_install_permissions, items); + for (const auto& arg : items) { + if (!this->CheckPermissions(arg, default_dir_mode_v)) { + std::ostringstream e; + e << this->FileCommand->GetError() + << " Set with CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS variable."; + this->FileCommand->SetError(e.str()); + return false; + } + } + + default_dir_mode = &default_dir_mode_v; + } + if (this->InstallType != cmInstallType_DIRECTORY) { if (!cmSystemTools::FileExists(destination.c_str())) { - if (!cmSystemTools::MakeDirectory(destination.c_str())) { + if (!cmSystemTools::MakeDirectory(destination, default_dir_mode)) { std::string errstring = "cannot create directory: " + destination + ". Maybe need administrative privileges."; this->FileCommand->SetError(errstring); @@ -2028,9 +2013,9 @@ bool cmFileCommand::HandleRPathChangeCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; - const char* oldRPath = CM_NULLPTR; - const char* newRPath = CM_NULLPTR; + const char* file = nullptr; + const char* oldRPath = nullptr; + const char* newRPath = nullptr; enum Doing { DoingNone, @@ -2118,7 +2103,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; + const char* file = nullptr; enum Doing { DoingNone, @@ -2182,8 +2167,8 @@ bool cmFileCommand::HandleRPathCheckCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; - const char* rpath = CM_NULLPTR; + const char* file = nullptr; + const char* rpath = nullptr; enum Doing { DoingNone, @@ -2241,16 +2226,16 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args) cmCommandArgumentGroup group; cmCAString readArg(&argHelper, "READ_ELF"); - cmCAString fileNameArg(&argHelper, CM_NULLPTR); + cmCAString fileNameArg(&argHelper, nullptr); cmCAString rpathArg(&argHelper, "RPATH", &group); cmCAString runpathArg(&argHelper, "RUNPATH", &group); cmCAString errorArg(&argHelper, "CAPTURE_ERROR", &group); - readArg.Follows(CM_NULLPTR); + readArg.Follows(nullptr); fileNameArg.Follows(&readArg); group.Follows(&fileNameArg); - argHelper.Parse(&args, CM_NULLPTR); + argHelper.Parse(&args, nullptr); if (!cmSystemTools::FileExists(fileNameArg.GetString(), true)) { std::ostringstream e; @@ -2284,10 +2269,9 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args) if (errorArg.GetString().empty()) { this->SetError(error); return false; - } else { - this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); - return true; } + this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); + return true; #endif } @@ -2439,7 +2423,7 @@ namespace { size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast<int>(size * nmemb); cmsys::ofstream* fout = static_cast<cmsys::ofstream*>(data); const char* chPtr = static_cast<char*>(ptr); fout->write(chPtr, realsize); @@ -2449,7 +2433,7 @@ size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data) size_t cmWriteToMemoryCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast<int>(size * nmemb); cmFileCommandVectorOfChar* vec = static_cast<cmFileCommandVectorOfChar*>(data); const char* chPtr = static_cast<char*>(ptr); @@ -2581,7 +2565,7 @@ public: } } - void release() { this->Easy = CM_NULLPTR; } + void release() { this->Easy = nullptr; } private: ::CURL* Easy; @@ -2617,9 +2601,12 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) std::string statusVar; bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY"); const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO"); + std::string netrc_level = this->Makefile->GetSafeDefinition("CMAKE_NETRC"); + std::string netrc_file = + this->Makefile->GetSafeDefinition("CMAKE_NETRC_FILE"); std::string expectedHash; std::string hashMatchMSG; - CM_AUTO_PTR<cmCryptoHash> hash; + std::unique_ptr<cmCryptoHash> hash; bool showProgress = false; std::string userpwd; @@ -2672,14 +2659,29 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) this->SetError("TLS_CAFILE missing file value."); return false; } + } else if (*i == "NETRC_FILE") { + ++i; + if (i != args.end()) { + netrc_file = *i; + } else { + this->SetError("DOWNLOAD missing file value for NETRC_FILE."); + return false; + } + } else if (*i == "NETRC") { + ++i; + if (i != args.end()) { + netrc_level = *i; + } else { + this->SetError("DOWNLOAD missing level value for NETRC."); + return false; + } } else if (*i == "EXPECTED_MD5") { ++i; if (i == args.end()) { this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5."); return false; } - hash = - CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(cmCryptoHash::AlgoMD5)); + hash = cm::make_unique<cmCryptoHash>(cmCryptoHash::AlgoMD5); hashMatchMSG = "MD5 sum"; expectedHash = cmSystemTools::LowerCase(*i); } else if (*i == "SHOW_PROGRESS") { @@ -2700,7 +2702,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) } std::string algo = i->substr(0, pos); expectedHash = cmSystemTools::LowerCase(i->substr(pos + 1)); - hash = CM_AUTO_PTR<cmCryptoHash>(cmCryptoHash::New(algo.c_str())); + hash = std::unique_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str())); if (!hash.get()) { std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: "; err += algo; @@ -2743,7 +2745,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) msg += "\""; if (!statusVar.empty()) { std::ostringstream result; - result << (int)0 << ";\"" << msg; + result << 0 << ";\"" << msg; this->Makefile->AddDefinition(statusVar, result.str().c_str()); } return true; @@ -2814,12 +2816,22 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) return false; } + // check to see if netrc parameters have been specified + // local command args takes precedence over CMAKE_NETRC* + netrc_level = cmSystemTools::UpperCase(netrc_level); + std::string const& netrc_option_err = + cmCurlSetNETRCOption(curl, netrc_level, netrc_file); + if (!netrc_option_err.empty()) { + this->SetError(netrc_option_err); + return false; + } + cmFileCommandVectorOfChar chunkDebug; - res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&fout); + res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fout); check_curl_result(res, "DOWNLOAD cannot set write data: "); - res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void*)&chunkDebug); + res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug); check_curl_result(res, "DOWNLOAD cannot set debug data: "); res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); @@ -2866,10 +2878,9 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) check_curl_result(res, "DOWNLOAD cannot set user password: "); } - struct curl_slist* headers = CM_NULLPTR; - for (std::vector<std::string>::const_iterator h = curl_headers.begin(); - h != curl_headers.end(); ++h) { - headers = ::curl_slist_append(headers, h->c_str()); + struct curl_slist* headers = nullptr; + for (std::string const& h : curl_headers) { + headers = ::curl_slist_append(headers, h.c_str()); } ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); @@ -2883,7 +2894,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) if (!statusVar.empty()) { std::ostringstream result; - result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\""; + result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) + << "\""; this->Makefile->AddDefinition(statusVar, result.str().c_str()); } @@ -2896,7 +2908,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) // Verify MD5 sum if requested: // - if (hash.get()) { + if (hash) { std::string actualHash = hash->HashFile(file); if (actualHash.empty()) { this->SetError("DOWNLOAD cannot compute hash on downloaded file"); @@ -2909,7 +2921,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) << " for file: [" << file << "]" << std::endl << " expected hash: [" << expectedHash << "]" << std::endl << " actual hash: [" << actualHash << "]" << std::endl - << " status: [" << (int)res << ";\"" + << " status: [" << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) << "\"]" << std::endl; if (!statusVar.empty() && res == 0) { @@ -2956,6 +2968,9 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) std::string statusVar; bool showProgress = false; std::string userpwd; + std::string netrc_level = this->Makefile->GetSafeDefinition("CMAKE_NETRC"); + std::string netrc_file = + this->Makefile->GetSafeDefinition("CMAKE_NETRC_FILE"); std::vector<std::string> curl_headers; @@ -2992,6 +3007,22 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) statusVar = *i; } else if (*i == "SHOW_PROGRESS") { showProgress = true; + } else if (*i == "NETRC_FILE") { + ++i; + if (i != args.end()) { + netrc_file = *i; + } else { + this->SetError("UPLOAD missing file value for NETRC_FILE."); + return false; + } + } else if (*i == "NETRC") { + ++i; + if (i != args.end()) { + netrc_level = *i; + } else { + this->SetError("UPLOAD missing level value for NETRC."); + return false; + } } else if (*i == "USERPWD") { ++i; if (i == args.end()) { @@ -3065,10 +3096,10 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) cmFileCommandVectorOfChar chunkResponse; cmFileCommandVectorOfChar chunkDebug; - res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunkResponse); + res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, &chunkResponse); check_curl_result(res, "UPLOAD cannot set write data: "); - res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void*)&chunkDebug); + res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug); check_curl_result(res, "UPLOAD cannot set debug data: "); res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); @@ -3124,10 +3155,19 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) check_curl_result(res, "UPLOAD cannot set user password: "); } - struct curl_slist* headers = CM_NULLPTR; - for (std::vector<std::string>::const_iterator h = curl_headers.begin(); - h != curl_headers.end(); ++h) { - headers = ::curl_slist_append(headers, h->c_str()); + // check to see if netrc parameters have been specified + // local command args takes precedence over CMAKE_NETRC* + netrc_level = cmSystemTools::UpperCase(netrc_level); + std::string const& netrc_option_err = + cmCurlSetNETRCOption(curl, netrc_level, netrc_file); + if (!netrc_option_err.empty()) { + this->SetError(netrc_option_err); + return false; + } + + struct curl_slist* headers = nullptr; + for (std::string const& h : curl_headers) { + headers = ::curl_slist_append(headers, h.c_str()); } ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); @@ -3141,14 +3181,15 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) if (!statusVar.empty()) { std::ostringstream result; - result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\""; + result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) + << "\""; this->Makefile->AddDefinition(statusVar, result.str().c_str()); } ::curl_global_cleanup(); fclose(fin); - fin = CM_NULLPTR; + fin = nullptr; if (!logVar.empty()) { std::string log; @@ -3185,15 +3226,15 @@ void cmFileCommand::AddEvaluationFile(const std::string& inputName, cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression outputGe(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputCge = + std::unique_ptr<cmCompiledGeneratorExpression> outputCge = outputGe.Parse(outputExpr); cmGeneratorExpression conditionGe(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> conditionCge = + std::unique_ptr<cmCompiledGeneratorExpression> conditionCge = conditionGe.Parse(condition); - this->Makefile->AddEvaluationFile(inputName, outputCge, conditionCge, - inputIsContent); + this->Makefile->AddEvaluationFile(inputName, std::move(outputCge), + std::move(conditionCge), inputIsContent); } bool cmFileCommand::HandleGenerateCommand(std::vector<std::string> const& args) |