diff options
| author | ruki <[email protected]> | 2020-09-15 23:19:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-09-15 23:19:23 +0800 |
| commit | 20aaf1318dfe5c71a62a627dbf7031379379e074 (patch) | |
| tree | 1b7565318913ec1a88d00efd1116d12dd08e9e35 | |
| parent | edb94735dc313f04af34bf1fe4c866e41de355de (diff) | |
improve to check the patch text
| -rw-r--r-- | xmake/actions/require/impl/action/patch_sources.lua | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/xmake/actions/require/impl/action/patch_sources.lua b/xmake/actions/require/impl/action/patch_sources.lua index d4ab76d07..e0874ed77 100644 --- a/xmake/actions/require/impl/action/patch_sources.lua +++ b/xmake/actions/require/impl/action/patch_sources.lua @@ -23,6 +23,26 @@ import("core.base.option") import("net.http") import("devel.git") +-- check sha256 +function _check_sha256(patch_hash, patch_file) + local ok = (patch_hash == hash.sha256(patch_file)) + if not ok and is_host("windows") then + -- `git pull` maybe will replace lf to crlf in the patch text automatically on windows. + -- so we need attempt to fix this sha256 + -- + -- @see + -- https://github.com/xmake-io/xmake-repo/pull/67 + -- https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf + -- + local tmpfile = os.tmpfile(patch_file) + os.cp(patch_file, tmpfile) + io.gsub(tmpfile, '\n', '\r\n') + ok = (patch_hash == hash.sha256(tmpfile)) + os.rm(tmpfile) + end + return ok +end + -- do patch function _patch(package, patch_url, patch_hash) @@ -39,7 +59,7 @@ function _patch(package, patch_url, patch_hash) -- the package file have been downloaded? local cached = true - if option.get("force") or not os.isfile(patch_file) or patch_hash ~= hash.sha256(patch_file) then + if option.get("force") or not os.isfile(patch_file) or not _check_sha256(patch_hash, patch_file) then -- no cached cached = false @@ -65,7 +85,7 @@ function _patch(package, patch_url, patch_hash) end -- check hash - if patch_hash and patch_hash ~= hash.sha256(patch_file) then + if patch_hash and not _check_sha256(patch_hash, patch_file) then raise("patch(%s): unmatched checksum!", patch_url) end end |
