diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-06 15:17:16 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-06 19:31:19 -0700 |
| commit | b87aeb77deb7b6cdc7e78d0b006243a15993e78c (patch) | |
| tree | 0e7996b4194d467e55dbd9e4f7c65c1642a09215 /toolsrc/src | |
| parent | 5d96ff1229d3e93f901215f054225d2859b07f5f (diff) | |
| download | vcpkg-b87aeb77deb7b6cdc7e78d0b006243a15993e78c.tar.gz vcpkg-b87aeb77deb7b6cdc7e78d0b006243a15993e78c.zip | |
[vcpkg.exe] Verify hash for already present files. Dont check for path twice
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/commands.fetch.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/toolsrc/src/vcpkg/commands.fetch.cpp b/toolsrc/src/vcpkg/commands.fetch.cpp index 1d2c67d67..cf19b4384 100644 --- a/toolsrc/src/vcpkg/commands.fetch.cpp +++ b/toolsrc/src/vcpkg/commands.fetch.cpp @@ -229,17 +229,31 @@ namespace vcpkg::Commands::Fetch fs.rename(to_path_partial, to_path); } + static void verify_hash(const VcpkgPaths& paths, + const std::string& url, + const fs::path& path, + const std::string& sha512) + { + const std::string actual_hash = Hash::get_file_hash(paths, path, "SHA512"); + Checks::check_exit(VCPKG_LINE_INFO, + sha512 == actual_hash, + "File does not have the expected hash:\n" + " url : [ %s ]\n" + " File path : [ %s ]\n" + " Expected hash : [ %s ]\n" + " Actual hash : [ %s ]\n", + url, + path.u8string(), + sha512, + actual_hash); + } + static void download_file(const VcpkgPaths& paths, const std::string& url, const fs::path& download_path, const std::string& sha512) { Files::Filesystem& fs = paths.get_filesystem(); - if (fs.exists(download_path)) - { - return; - } - const std::string download_path_part = download_path.u8string() + ".part"; std::error_code ec; fs.remove(download_path_part, ec); @@ -247,19 +261,7 @@ namespace vcpkg::Commands::Fetch R"(curl -L '%s' --create-dirs --output '%s')", url, download_path_part)); Checks::check_exit(VCPKG_LINE_INFO, code == 0, "Could not download %s", url); - const std::string actual_hash = Hash::get_file_hash(paths, download_path_part, "SHA512"); - Checks::check_exit(VCPKG_LINE_INFO, - sha512 == actual_hash, - "File does not have the expected hash:\n" - " url : [ %s ]\n" - " File path : [ %s ]\n" - " Expected hash : [ %s ]\n" - " Actual hash : [ %s ]\n", - url, - download_path.u8string(), - sha512, - actual_hash); - + verify_hash(paths, url, download_path_part, sha512); fs.rename(download_path_part, download_path); } @@ -302,6 +304,10 @@ namespace vcpkg::Commands::Fetch download_file(paths, tool_data.url, tool_data.download_path, tool_data.sha512); System::println("Downloading %s... done.", tool_name); } + else + { + verify_hash(paths, tool_data.url, tool_data.download_path, tool_data.sha512); + } System::println("Extracting %s...", tool_name); extract_archive(paths, tool_data.download_path, tool_data.tool_dir_path); |
