summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Croce2024-09-28 23:01:01 +0000
committerChristian Marangi2024-10-27 13:24:32 +0000
commit65560de58de7a3cde8f960849e3c7c640b9456d8 (patch)
tree738602190794968d78854efd236e8fa62373ec29
parent5fdd18243eecf405737939bde553e14b6eec0043 (diff)
downloadopenwrt-65560de58de7a3cde8f960849e3c7c640b9456d8.tar.gz
scripts/download.pl: read file natively
Read files natively instead of execing /bin/cat. Signed-off-by: Matteo Croce <teknoraver@meta.com> Link: https://github.com/openwrt/openwrt/pull/16784 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
-rwxr-xr-xscripts/download.pl14
1 files changed, 10 insertions, 4 deletions
diff --git a/scripts/download.pl b/scripts/download.pl
index c6c9b8e56c..9966f9f1e6 100755
--- a/scripts/download.pl
+++ b/scripts/download.pl
@@ -32,6 +32,12 @@ my $download_tool;
$url_filename or $url_filename = $filename;
+sub cat {
+ open my $fh, '<', $1 or die "Can't open file $!";
+ read $fh, my $file_content, -s $fh;
+ return $file_content;
+}
+
sub localmirrors {
my @mlist;
open LM, "$scriptdir/localmirrors" and do {
@@ -203,7 +209,7 @@ sub download
copy($link, "$target/$filename.dl");
$hash_cmd and do {
- if (system("cat '$target/$filename.dl' | $hash_cmd > '$target/$filename.hash'")) {
+ if (system("$hash_cmd '$target/$filename.dl' > '$target/$filename.hash'")) {
print("Failed to generate hash for $filename\n");
return;
}
@@ -233,7 +239,7 @@ sub download
}
$hash_cmd and do {
- my $sum = `cat "$target/$filename.hash"`;
+ my $sum = cat("$target/$filename.hash");
$sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n";
$sum = $1;
@@ -299,11 +305,11 @@ projectsmirrors '@OPENWRT';
if (-f "$target/$filename") {
$hash_cmd and do {
- if (system("cat '$target/$filename' | $hash_cmd > '$target/$filename.hash'")) {
+ if (system("$hash_cmd '$target/$filename' > '$target/$filename.hash'")) {
die "Failed to generate hash for $filename\n";
}
- my $sum = `cat "$target/$filename.hash"`;
+ my $sum = cat("$target/$filename.hash");
$sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n";
$sum = $1;