Skip to content

Commit 631ac4d

Browse files
committed
Fix compatibility issue, again.
1 parent bb36583 commit 631ac4d

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.3.2] - 2023-07-18
10+
11+
### Fixed
12+
13+
* Fix compatibility issue, again.
14+
915
## [2.3.1] - 2023-07-18
1016

1117
### Fixed

bin/setup-environment

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ my $workspace = {
4242
settings => {},
4343
};
4444

45+
sub _check_integrity {
46+
my ($integrity, $file_or_content) = @_;
47+
48+
my ($algorithm) = $integrity =~ m{\Asha(\d+)};
49+
my $sha = Digest::SHA->new($algorithm);
50+
if (ref $file_or_content) {
51+
52+
$sha->addfile($file_or_content);
53+
} else {
54+
$sha->add($file_or_content);
55+
}
56+
my $digest = $sha->b64digest;
57+
$digest .= ('=' x ((4 - (length($digest) % 4)) % 4));
58+
my $file_integrity = "sha256-" . $digest;
59+
60+
return $integrity eq ("sha$algorithm-" . $digest);
61+
}
62+
4563
sub handle_recipe {
4664
my $data = shift;
4765

@@ -70,28 +88,17 @@ sub handle_recipe {
7088
my $rel_path = catfile($k, $basename);
7189
my $full_path = catfile($archive_dir, $rel_path);
7290

73-
my ($algorithm) = $integrity =~ m{\Asha(\d+)};
74-
my $sha = Digest::SHA->new($algorithm);
75-
76-
if (-f $full_path) {
77-
$sha->addfile(IO::File->new($full_path, 'r'));
78-
my $digest = $sha->b64digest;
79-
$digest .= ('=' x ((4 - (length($digest) % 4)) % 4));
80-
my $file_integrity = "sha$algorithm-" . $digest;
81-
if ($file_integrity eq $integrity) {
82-
$archives .= " $rel_path";
83-
next;
84-
}
91+
if (-f $full_path && _check_integrity($integrity, IO::File->new($full_path, 'r'))) {
92+
$archives .= " $rel_path";
93+
next;
8594
}
8695

8796
mkpath(dirname($full_path));
8897
my $response = HTTP::Tiny->new->get($url);
8998
die "Failed: @{[Dumper($response)]}"
9099
unless $response->{success} && length $response->{content};
91100

92-
$sha->add($response->{content});
93-
my $digest = "sha$algorithm-" . $sha->base64_padded_digest;
94-
if ($digest ne $integrity) {
101+
if (!_check_integrity($integrity, $response->{content})) {
95102
die "intergrity check failed: $url";
96103
}
97104

0 commit comments

Comments
 (0)