Skip to content

Commit 4519022

Browse files
committed
scripts/download.pl: read file natively
Read files natively instead of execing /bin/cat. Signed-off-by: Matteo Croce <teknoraver@meta.com>
1 parent b77fa45 commit 4519022

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scripts/download.pl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232

3333
$url_filename or $url_filename = $filename;
3434

35+
sub cat {
36+
open my $fh, '<', $_[0] or die "Can't open file $!";
37+
read $fh, my $file_content, -s $fh;
38+
return $file_content;
39+
}
40+
3541
sub localmirrors {
3642
my @mlist;
3743
open LM, "$scriptdir/localmirrors" and do {
@@ -203,7 +209,7 @@ sub download
203209
copy($link, "$target/$filename.dl");
204210

205211
$hash_cmd and do {
206-
if (system("cat '$target/$filename.dl' | $hash_cmd > '$target/$filename.hash'")) {
212+
if (system("$hash_cmd '$target/$filename.dl' > '$target/$filename.hash'")) {
207213
print("Failed to generate hash for $filename\n");
208214
return;
209215
}
@@ -233,7 +239,7 @@ sub download
233239
}
234240

235241
$hash_cmd and do {
236-
my $sum = `cat "$target/$filename.hash"`;
242+
my $sum = cat("$target/$filename.hash");
237243
$sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n";
238244
$sum = $1;
239245

@@ -299,11 +305,11 @@ sub cleanup
299305

300306
if (-f "$target/$filename") {
301307
$hash_cmd and do {
302-
if (system("cat '$target/$filename' | $hash_cmd > '$target/$filename.hash'")) {
308+
if (system("$hash_cmd '$target/$filename' > '$target/$filename.hash'")) {
303309
die "Failed to generate hash for $filename\n";
304310
}
305311

306-
my $sum = `cat "$target/$filename.hash"`;
312+
my $sum = cat("$target/$filename.hash");
307313
$sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n";
308314
$sum = $1;
309315

0 commit comments

Comments
 (0)