diff options
Diffstat (limited to 'Source/cmFileCommand.cxx')
| -rw-r--r-- | Source/cmFileCommand.cxx | 128 |
1 files changed, 82 insertions, 46 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fb15a1b..3c234a6 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -15,6 +15,7 @@ #include <vector> #include <cm/memory> +#include <cm/optional> #include <cm/string_view> #include <cmext/algorithm> #include <cmext/string_view> @@ -86,7 +87,7 @@ bool HandleWriteImpl(std::vector<std::string> const& args, bool append, std::string e = "attempted to write a file: " + fileName + " into a source directory."; status.SetError(e); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } std::string dir = cmSystemTools::GetFilenamePath(fileName); @@ -290,7 +291,7 @@ bool HandleStringsCommand(std::vector<std::string> const& args, } // Get the variable in which to store the results. - std::string outVar = args[2]; + std::string const& outVar = args[2]; // Parse the options. enum @@ -840,7 +841,7 @@ bool HandleMakeDirectoryCommand(std::vector<std::string> const& args, std::string e = "attempted to create a directory: " + *cdir + " into a source directory."; status.SetError(e); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (!cmSystemTools::MakeDirectory(*cdir)) { @@ -870,7 +871,7 @@ bool HandleTouchImpl(std::vector<std::string> const& args, bool create, std::string e = "attempted to touch a file: " + tfile + " in a source directory."; status.SetError(e); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (!cmSystemTools::Touch(tfile, create)) { @@ -1615,8 +1616,8 @@ size_t cmWriteToMemoryCallback(void* ptr, size_t size, size_t nmemb, return realsize; } -size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr, - size_t size, void* data) +int cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr, + size_t size, void* data) { cmFileCommandVectorOfChar& vec = *static_cast<cmFileCommandVectorOfChar*>(data); @@ -1784,6 +1785,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, std::string userpwd; std::vector<std::string> curl_headers; + std::vector<std::pair<std::string, cm::optional<std::string>>> curl_ranges; while (i != args.end()) { if (*i == "TIMEOUT") { @@ -1874,7 +1876,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, } std::string algo = i->substr(0, pos); expectedHash = cmSystemTools::LowerCase(i->substr(pos + 1)); - hash = std::unique_ptr<cmCryptoHash>(cmCryptoHash::New(algo)); + hash = cmCryptoHash::New(algo); if (!hash) { std::string err = cmStrCat("DOWNLOAD EXPECTED_HASH given unknown ALGO: ", algo); @@ -1896,6 +1898,27 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, return false; } curl_headers.push_back(*i); + } else if (*i == "RANGE_START") { + ++i; + if (i == args.end()) { + status.SetError("DOWNLOAD missing value for RANGE_START."); + return false; + } + curl_ranges.emplace_back(*i, cm::nullopt); + } else if (*i == "RANGE_END") { + ++i; + if (curl_ranges.empty()) { + curl_ranges.emplace_back("0", *i); + } else { + auto& last_range = curl_ranges.back(); + if (!last_range.second.has_value()) { + last_range.second = *i; + } else { + status.SetError("Multiple RANGE_END values is provided without " + "the corresponding RANGE_START."); + return false; + } + } } else if (file.empty()) { file = *i; } else { @@ -1905,6 +1928,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, } ++i; } + // Can't calculate hash if we don't save the file. // TODO Incrementally calculate hash in the write callback as the file is // being downloaded so this check can be relaxed. @@ -1990,6 +2014,13 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, check_curl_result(res, "DOWNLOAD cannot set TLS/SSL Verify off: "); } + for (const auto& range : curl_ranges) { + std::string curl_range = range.first + '-' + + (range.second.has_value() ? range.second.value() : ""); + res = ::curl_easy_setopt(curl, CURLOPT_RANGE, curl_range.c_str()); + check_curl_result(res, "DOWNLOAD cannot set range: "); + } + // check to see if a CAINFO file has been specified // command arg comes first std::string const& cainfo_err = cmCurlSetCAInfo(curl, cainfo); @@ -2737,7 +2768,7 @@ bool HandleLockCommand(std::vector<std::string> const& args, MessageType::FATAL_ERROR, cmStrCat("directory\n \"", parentDir, "\"\ncreation failed (check permissions).")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } FILE* file = cmsys::SystemTools::Fopen(path, "w"); @@ -2746,7 +2777,7 @@ bool HandleLockCommand(std::vector<std::string> const& args, MessageType::FATAL_ERROR, cmStrCat("file\n \"", path, "\"\ncreation failed (check permissions).")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } fclose(file); @@ -2770,7 +2801,7 @@ bool HandleLockCommand(std::vector<std::string> const& args, fileLockResult = lockPool.LockProcessScope(path, timeout); break; default: - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -2781,7 +2812,7 @@ bool HandleLockCommand(std::vector<std::string> const& args, status.GetMakefile().IssueMessage( MessageType::FATAL_ERROR, cmStrCat("error locking file\n \"", path, "\"\n", result, ".")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3016,7 +3047,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, status.SetError( cmStrCat("GET_RUNTIME_DEPENDENCIES is not supported on system \"", platform, "\"")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3084,7 +3115,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, auto argIt = unrecognizedArguments.begin(); if (argIt != unrecognizedArguments.end()) { status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\"")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3106,7 +3137,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, if (kwend != kwbegin) { status.SetError(cmStrCat("Keywords missing values:\n ", cmJoin(cmMakeRange(kwbegin, kwend), "\n "))); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3118,13 +3149,13 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, std::move(parsedArgs.PostExcludeFiles), std::move(parsedArgs.PostExcludeFilesStrict)); if (!archive.Prepare()) { - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (!archive.GetRuntimeDependencies( parsedArgs.Executables, parsedArgs.Libraries, parsedArgs.Modules)) { - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3165,7 +3196,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, e << "\n " << path; } status.SetError(e.str()); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3181,7 +3212,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args, e << "\n " << path; } status.SetError(e.str()); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3235,7 +3266,7 @@ bool HandleConfigureCommand(std::vector<std::string> const& args, if (argIt != unrecognizedArguments.end()) { status.SetError( cmStrCat("CONFIGURE Unrecognized argument: \"", *argIt, "\"")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3247,7 +3278,7 @@ bool HandleConfigureCommand(std::vector<std::string> const& args, e) != keywordsMissingArguments.end(); if (optionHasNoValue) { status.SetError(cmStrCat("CONFIGURE ", e, " option needs a value.")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3258,7 +3289,7 @@ bool HandleConfigureCommand(std::vector<std::string> const& args, parsedKeywords.end(); if (!optionGiven) { status.SetError(cmStrCat("CONFIGURE ", e, " option is mandatory.")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3373,7 +3404,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, auto argIt = unrecognizedArguments.begin(); if (argIt != unrecognizedArguments.end()) { status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\"")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3385,7 +3416,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, if (kwend != kwbegin) { status.SetError(cmStrCat("Keywords missing values:\n ", cmJoin(cmMakeRange(kwbegin, kwend), "\n "))); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3397,7 +3428,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, !cm::contains(knownFormats, parsedArgs.Format)) { status.SetError( cmStrCat("archive format ", parsedArgs.Format, " not supported")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3406,7 +3437,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, cm::contains(zipFileFormats, parsedArgs.Format)) { status.SetError(cmStrCat("archive format ", parsedArgs.Format, " does not support COMPRESSION arguments")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3424,7 +3455,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, } else if (!parsedArgs.Compression.empty()) { status.SetError(cmStrCat("compression type ", parsedArgs.Compression, " is not supported")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3435,7 +3466,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, status.SetError(cmStrCat("compression level ", parsedArgs.CompressionLevel, " should be in range 0 to 9")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } compressionLevel = std::stoi(parsedArgs.CompressionLevel); @@ -3443,21 +3474,21 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, status.SetError(cmStrCat("compression level ", parsedArgs.CompressionLevel, " should be in range 0 to 9")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (compress == cmSystemTools::TarCompressNone) { status.SetError(cmStrCat("compression level is not supported for " "compression \"None\"", parsedArgs.Compression)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } if (parsedArgs.Paths.empty()) { status.SetError("ARCHIVE_CREATE requires a non-empty list of PATHS"); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3465,7 +3496,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args, parsedArgs.Verbose, parsedArgs.MTime, parsedArgs.Format, compressionLevel)) { status.SetError(cmStrCat("failed to compress: ", parsedArgs.Output)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3482,6 +3513,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, bool ListOnly = false; std::string Destination; std::vector<std::string> Patterns; + bool Touch = false; }; static auto const parser = cmArgumentParser<Arguments>{} @@ -3489,7 +3521,8 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, .Bind("VERBOSE"_s, &Arguments::Verbose) .Bind("LIST_ONLY"_s, &Arguments::ListOnly) .Bind("DESTINATION"_s, &Arguments::Destination) - .Bind("PATTERNS"_s, &Arguments::Patterns); + .Bind("PATTERNS"_s, &Arguments::Patterns) + .Bind("TOUCH"_s, &Arguments::Touch); std::vector<std::string> unrecognizedArguments; std::vector<std::string> keywordsMissingValues; @@ -3499,7 +3532,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, auto argIt = unrecognizedArguments.begin(); if (argIt != unrecognizedArguments.end()) { status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\"")); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3510,7 +3543,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, if (kwend != kwbegin) { status.SetError(cmStrCat("Keywords missing values:\n ", cmJoin(cmMakeRange(kwbegin, kwend), "\n "))); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3520,7 +3553,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, if (!cmSystemTools::ListTar(inFile, parsedArgs.Patterns, parsedArgs.Verbose)) { status.SetError(cmStrCat("failed to list: ", inFile)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } else { @@ -3534,7 +3567,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, if (!cmSystemTools::MakeDirectory(destDir)) { status.SetError(cmStrCat("failed to create directory: ", destDir)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3548,14 +3581,17 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args, if (workdir.Failed()) { status.SetError( cmStrCat("failed to change working directory to: ", destDir)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } - if (!cmSystemTools::ExtractTar(inFile, parsedArgs.Patterns, - parsedArgs.Verbose)) { + if (!cmSystemTools::ExtractTar( + inFile, parsedArgs.Patterns, + parsedArgs.Touch ? cmSystemTools::cmTarExtractTimestamps::No + : cmSystemTools::cmTarExtractTimestamps::Yes, + parsedArgs.Verbose)) { status.SetError(cmStrCat("failed to extract: ", inFile)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3569,7 +3605,7 @@ bool ValidateAndConvertPermissions(const std::vector<std::string>& permissions, for (const auto& i : permissions) { if (!cmFSPermissions::stringToModeT(i, perms)) { status.SetError(i + " is an invalid permission specifier"); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } } @@ -3581,7 +3617,7 @@ bool SetPermissions(const std::string& filename, const mode_t& perms, { if (!cmSystemTools::SetPermissions(filename, perms)) { status.SetError("Failed to set permissions for " + filename); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } return true; @@ -3621,7 +3657,7 @@ bool HandleChmodCommandImpl(std::vector<std::string> const& args, bool recurse, parsedArgs.DirectoryPermissions.empty()) // no permissions given { status.SetError("No permissions given"); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } @@ -3630,14 +3666,14 @@ bool HandleChmodCommandImpl(std::vector<std::string> const& args, bool recurse, { status.SetError("Remove either PERMISSIONS or FILE_PERMISSIONS or " "DIRECTORY_PERMISSIONS from the invocation"); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (!keywordsMissingValues.empty()) { for (const auto& i : keywordsMissingValues) { status.SetError(i + " is not given any arguments"); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); } return false; } @@ -3676,7 +3712,7 @@ bool HandleChmodCommandImpl(std::vector<std::string> const& args, bool recurse, for (const auto& i : allPathEntries) { if (!(cmSystemTools::FileExists(i) || cmSystemTools::FileIsDirectory(i))) { status.SetError(cmStrCat("does not exist:\n ", i)); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } |
