From 157d2ac168fda1e85407ebf502b1def578f05c08 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 12 Apr 2016 06:08:56 +0000 Subject: refactor downloading, verify downloaded tlpdb git-svn-id: svn://tug.org/texlive/trunk@40437 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/TLPDB.pm | 57 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'Master/tlpkg/TeXLive/TLPDB.pm') diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm index 3bb5801f623..8eb4411cc4d 100644 --- a/Master/tlpkg/TeXLive/TLPDB.pm +++ b/Master/tlpkg/TeXLive/TLPDB.pm @@ -299,31 +299,30 @@ sub from_file { # actually load the TLPDB if ($path =~ m;^((http|ftp)://|file:\/\/*);) { debug("TLPDB.pm: trying to initialize from $path\n"); + # now $xzfh filehandle is open, the file created + # TLUtils::download_file will just overwrite what is there + # on windows that doesn't work, so we close the fh immediately + # this creates a short loophole, but much better than before anyway + my $tlpdbfh; + ($tlpdbfh, $tlpdbfile) = tempfile(); + # same as above + close($tlpdbfh); + my $tlpdbfile_quote = $tlpdbfile; + if (win32()) { + $tlpdbfile =~ s!/!\\!g; + } + $tlpdbfile_quote = "\"$tlpdbfile\""; # if we have xzdec available we try the xz file + my $xz_succeeded = 0 ; if (defined($::progs{'xzdec'})) { # we first try the xz compressed file - # - # we have to create a temp file to download to my ($xzfh, $xzfile) = tempfile(); - # now $xzfh filehandle is open, the file created - # TLUtils::download_file will just overwrite what is there - # on windows that doesn't work, so we close the fh immediately - # this creates a short loophole, but much better than before anyway close($xzfh); my $xzfile_quote = $xzfile; - # this is a variable of the whole sub as we have to remove the file - # before returning - my $tlpdbfh; - ($tlpdbfh, $tlpdbfile) = tempfile(); - # same as above - close($tlpdbfh); - my $tlpdbfile_quote = $tlpdbfile; if (win32()) { $xzfile =~ s!/!\\!g; - $tlpdbfile =~ s!/!\\!g; } $xzfile_quote = "\"$xzfile\""; - $tlpdbfile_quote = "\"$tlpdbfile\""; my $xzdec = TeXLive::TLUtils::quotify_path_with_spaces($::progs{'xzdec'}); debug("trying to download $path.xz to $xzfile\n"); my $ret = TeXLive::TLUtils::download_file("$path.xz", "$xzfile"); @@ -338,29 +337,33 @@ sub from_file { debug("un-xzing $xzfile failed, trying plain file\n"); # to be sure we unlink the xz file and the tlpdbfile unlink($xzfile); - unlink($tlpdbfile); } else { unlink($xzfile); - # verify checksum - # TODO TODO TODO VERIFY - # either here, but we need to do the same alos 10lines down - # there when downloading the tlpdb file directly into a pipe!!! - #TeXLive::TLUtils::verify_download($tlpdbfile, $path); - open($retfh, "<$tlpdbfile") || die "$0: open($tlpdbfile) failed: $!"; + $xz_succeeded = 1; debug("found the uncompressed xz file\n"); } } } else { debug("no xzdec defined, not trying tlpdb.xz ...\n"); } - if (!defined($retfh)) { + if (!$xz_succeeded) { debug("TLPDB: downloading $path.xz didn't succeed, try $path\n"); - # xz did not succeed, so try the normal file - $retfh = TeXLive::TLUtils::download_file($path, "|"); - if (!$retfh) { - die "open tlpdb($path) failed: $!"; + my $ret = TeXLive::TLUtils::download_file($path, $tlpdbfile); + # better to check both, the return value AND the existence of the file + if ($ret && (-r "$tlpdbfile")) { + # do nothing + } else { + unlink($tlpdbfile); + die "$0: open tlpdb($path) failed: $!"; } } + # if we are still here, then either the xz version was downloaded + # and unpacked, or the non-xz version was downloaded, and in both + # cases the result, i.e., the unpackaged tlpdb, is in $tlpdbfile + # + # before we open and proceed, verify the downloaded file + TeXLive::TLUtils::verify_download($tlpdbfile, $path); + open($retfh, "<$tlpdbfile") || die "$0: open($tlpdbfile) failed: $!"; } else { open(TMP, "<$path") || die "$0: open($path) failed: $!"; $retfh = \*TMP; -- cgit v1.2.3