Skip to content

Commit

Permalink
Fix opam installing packages without checking their checksum when the…
Browse files Browse the repository at this point in the history
… local cache is corrupted in some cases
  • Loading branch information
kit-ty-kate committed May 8, 2023
1 parent 84f8d14 commit d7e043e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/repository/opamRepository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ let fetch_from_cache =
failwith "Version control not allowed as cache URL"
in
try
let hit_checksum, hit_file =
let hit_file =
OpamStd.List.find_map (fun ck ->
let f = cache_file cache_dir ck in
if OpamFilename.exists f then Some (ck, f) else None)
if OpamFilename.exists f then Some f else None)
checksums
in
if List.for_all
(fun ck -> ck = hit_checksum ||
OpamHash.check_file (OpamFilename.to_string hit_file) ck)
(fun ck -> OpamHash.check_file (OpamFilename.to_string hit_file) ck)
checksums
then Done (Up_to_date (hit_file, OpamUrl.empty))
else mismatch hit_file
Expand Down
18 changes: 6 additions & 12 deletions tests/reftests/local-cache.test
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,12 @@ The following actions will be performed:
- install good-sha256 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved good-sha256.1 (cached)
[ERROR] The compilation of good-sha256.1 failed at "test -f hello".



[ERROR] Conflicting file hashes, or broken or compromised cache!
- sha256=hash (MISMATCH)

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build good-sha256 1
+-
- No changes have been performed
# Return code 31 #
-> retrieved good-sha256.1 (file://${BASEDIR}/archive.tgz)
-> installed good-sha256.1
Done.
### sh check-cache.sh
MD5: link, to sha256 archive
SHA256: archive, with mismatching checksum
SHA256: archive, with matching checksum

0 comments on commit d7e043e

Please sign in to comment.