Skip to content

Commit

Permalink
Make tree hash mismatch fatal again and use
Browse files Browse the repository at this point in the history
    JULIA_PKG_IGNORE_HASHES=1
to manually ignore them, fixes #2317.
  • Loading branch information
fredrikekre committed Jan 8, 2021
1 parent 9750a21 commit 74c9ec5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,22 @@ function download_artifact(
msg = "Tree Hash Mismatch!\n"
msg *= " Expected git-tree-sha1: $(bytes2hex(tree_hash.bytes))\n"
msg *= " Calculated git-tree-sha1: $(bytes2hex(calc_hash.bytes))"
# Since tree hash calculation is still broken on some systems, e.g. Pkg.jl#1860,
# and Pkg.jl#2317 so we allow setting JULIA_PKG_IGNORE_HASHES=1 to ignore the
# error and move the artifact to the expected location and return true
ignore_hash = get(ENV, "JULIA_PKG_IGNORE_HASHES", nothing) == "1"
if ignore_hash
msg *= "\n\$JULIA_PKG_IGNORE_HASHES is set to 1: ignoring error and moving artifact to the expected location"
end
@error(msg)
# Tree hash calculation is still broken on some systems, e.g. Pkg.jl#1860,
# so we return true here and only raise the warning on the lines above.
# return false
if ignore_hash
# Move it to the location we expected
src = artifact_path(calc_hash; honor_overrides=false)
dst = artifact_path(tree_hash; honor_overrides=false)
mv(src, dst; force=true)
return true
end
return false
end
end

Expand Down
15 changes: 9 additions & 6 deletions test/artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,20 @@ end

# Next, test incorrect download errors
if !Sys.iswindows()
mktempdir() do dir
for ignore_hash in (false, true); withenv("JULIA_PKG_IGNORE_HASHES" => ignore_hash ? "1" : nothing) do; mktempdir() do dir
with_artifacts_directory(dir) do
@test artifact_meta("broken_artifact", joinpath(badifact_dir, "incorrect_gitsha.toml")) != nothing
@test_logs (:error, r"Tree Hash Mismatch!") match_mode=:any begin
# Only warn on wrong tree hash for now (see Pkg.jl#1885)
# @test_throws ErrorException ensure_artifact_installed("broken_artifact", joinpath(badifact_dir, "incorrect_gitsha.toml"))
path = ensure_artifact_installed("broken_artifact", joinpath(badifact_dir, "incorrect_gitsha.toml"))
@test endswith(path, "0000000000000000000000000000000000000000")
if !ignore_hash
@test_throws ErrorException ensure_artifact_installed("broken_artifact", joinpath(badifact_dir, "incorrect_gitsha.toml"))
else
path = ensure_artifact_installed("broken_artifact", joinpath(badifact_dir, "incorrect_gitsha.toml"))
@test endswith(path, "0000000000000000000000000000000000000000")
@test isdir(path)
end
end
end
end
end end end
end

mktempdir() do dir
Expand Down

0 comments on commit 74c9ec5

Please sign in to comment.