5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-03 09:17:36 +03:00

tools: download file: add a verification sub as option

so that a caller can do additional verification on the downloaded or
extracted file

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Tested-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Dominik Csapak 2024-11-18 15:31:11 +01:00 committed by Thomas Lamprecht
parent d8582cd045
commit b0061fd1b6

View File

@ -2061,6 +2061,8 @@ sub safe_compare {
# https_proxy
# verify_certificates - if 0 (false) we tell wget to ignore untrusted TLS certs. Default to true
# md5sum|sha(1|224|256|384|512)sum - the respective expected checksum string
# assert_file_validity - a subroutine to verify the extracted/downloaded file. gets the tmp path as parameter
# should die when the downloaded file is not valid
sub download_file_from_url {
my ($dest, $url, $opts) = @_;
@ -2149,6 +2151,11 @@ sub download_file_from_url {
$tmp_download = $tmp_decomp;
}
if (my $assertion = $opts->{assert_file_validity}) {
eval { $assertion->($tmp_download); };
die "failed to verify file: $@" if $@;
}
rename($tmp_download, $dest) or die "unable to rename temporary file: $!\n";
};
if (my $err = $@) {