From 32404eee694266a23a5d8a2c2f004d68c1d79195 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 4 Apr 2018 19:52:14 -0700 Subject: [vcpkgTools.xml] Verify the version field --- toolsrc/src/vcpkg/commands.fetch.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'toolsrc') diff --git a/toolsrc/src/vcpkg/commands.fetch.cpp b/toolsrc/src/vcpkg/commands.fetch.cpp index 10153293c..d2634a5f0 100644 --- a/toolsrc/src/vcpkg/commands.fetch.cpp +++ b/toolsrc/src/vcpkg/commands.fetch.cpp @@ -50,6 +50,7 @@ namespace vcpkg::Commands::Fetch static constexpr StringLiteral OS_STRING = "linux"; #endif + static const std::string XML_VERSION = "1"; static const fs::path XML_PATH = paths.scripts / "vcpkgTools.xml"; const auto maybe_get_string_inside_tags = [](const std::string& input, @@ -70,6 +71,7 @@ namespace vcpkg::Commands::Fetch return match[1]; }; + static const std::regex XML_VERSION_REGEX{R"###()###"}; static const std::string XML = paths.get_filesystem().read_contents(XML_PATH).value_or_exit(VCPKG_LINE_INFO); static const std::regex VERSION_REGEX{R"###(([\s\S]*?))###"}; static const std::regex EXE_RELATIVE_PATH_REGEX{ @@ -78,6 +80,17 @@ namespace vcpkg::Commands::Fetch Strings::format(R"###(([\s\S]*?))###")}; static const std::regex URL_REGEX{Strings::format(R"###(([\s\S]*?))###")}; + std::smatch match_xml_version; + const bool has_xml_version = std::regex_search(XML.cbegin(), XML.cend(), match_xml_version, XML_VERSION_REGEX); + Checks::check_exit( + VCPKG_LINE_INFO, has_xml_version, "Could not find in %s", XML_PATH.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, + XML_VERSION == match_xml_version[1], + "Expected %s version: [%s], but was [%s]. Please re-run bootstrap-vcpkg.", + XML_PATH.generic_string(), + XML_VERSION, + match_xml_version[1]); + const std::regex tool_regex{ Strings::format(R"###(([\s\S]*?)<\/tool>)###", tool, OS_STRING)}; -- cgit v1.2.3