diff options
author | Norbert Preining <preining@logic.at> | 2008-06-30 16:37:31 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2008-06-30 16:37:31 +0000 |
commit | a210df813ed206966a0f02b1e3ec47370d306c26 (patch) | |
tree | dc4d8501c7c1d9f69e7710366ddb56e7255cf5cf /Master/tlpkg/TeXLive/TLUtils.pm | |
parent | 18bb1e2c2cf25f1d0e33edb438a899f6a80cae02 (diff) |
adding support for md5 sums
git-svn-id: svn://tug.org/texlive/trunk@9115 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLUtils.pm')
-rw-r--r-- | Master/tlpkg/TeXLive/TLUtils.pm | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 3968c18bcae..59ab8bd92d8 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -66,6 +66,7 @@ C<TeXLive::TLUtils> -- utilities used in the TeX Live infrastructure TeXLive::TLUtils::kpsewhich; TeXLive::TLUtils::conv_to_win_path($path); TeXLive::TLUtils::give_ctan_mirror($path); + TeXLive::TLUtils::tlmd5($path); =head1 DESCRIPTION @@ -115,6 +116,7 @@ BEGIN { &welcome &welcome_paths &give_ctan_mirror + &tlmd5 ); @EXPORT = qw(setup_programs download_file info log debug ddebug tlwarn process_logging_options win32); } @@ -122,6 +124,7 @@ BEGIN { use TeXLive::TLConfig; use Getopt::Long; +use Digest::MD5; $::opt_verbosity = 0; @@ -622,7 +625,7 @@ sub install_packages { } elsif (&media eq 'NET') { $container = "$TeXLiveURL/$NetArchive/$package.$DefaultContainerExtension"; } - install_package($container, $tlpobj->containersize,\@installfiles,$totlpdb->root,$vars{'this_platform'}); + install_package($container, $tlpobj->containersize, $tlpobj->containermd5, \@installfiles,$totlpdb->root,$vars{'this_platform'}); # if we are installing from CD or NET we have to fetch the respective # source and doc packages $pkg.source and $pkg.doc and install them, too if ((&media eq 'NET') || (&media eq 'CD')) { @@ -635,13 +638,13 @@ sub install_packages { ($package !~ m/\./) && $tlpobj->srcfiles) { my $srccontainer = $container; $srccontainer =~ s/(\.tar\.lzma|\.zip)$/.source$1/; - install_package($srccontainer, $tlpobj->srccontainersize,\@installfiles,$totlpdb->root,$vars{'this_platform'}); + install_package($srccontainer, $tlpobj->srccontainersize, $tlpobj->srccontainermd5, \@installfiles,$totlpdb->root,$vars{'this_platform'}); } if ($container_doc_split && $real_opt_doc && ($package !~ m/\./) && $tlpobj->docfiles) { my $doccontainer = $container; $doccontainer =~ s/(\.tar\.lzma|\.zip)$/.doc$1/; - install_package($doccontainer, $tlpobj->doccontainersize, \@installfiles,$totlpdb->root,$vars{'this_platform'}); + install_package($doccontainer, $tlpobj->doccontainersize, $tlpobj->doccontainermd5, \@installfiles,$totlpdb->root,$vars{'this_platform'}); } } # we don't want to have wrong information in the tlpdb, so remove the @@ -693,7 +696,7 @@ is not taken into account (should be fixed!). =cut sub install_package { - my ($what, $whatsize, $filelistref, $target, $platform) = @_; + my ($what, $whatsize, $whatmd5, $filelistref, $target, $platform) = @_; my @filelist = @$filelistref; @@ -737,14 +740,41 @@ sub install_package { my $gotfiledone = 0; if (-r $lzmafile) { # check that the downloaded file is not partial - my $size = (stat $lzmafile)[7]; - if ($size == $whatsize) { - debug("Reusing already downloaded container $lzmafile\n"); - $gotfiledone = 1; + if ($whatsize >= 0) { + # we have the size given, so check that first + my $size = (stat $lzmafile)[7]; + if ($size == $whatsize) { + # we want to check also the md5sum if we have it present + if ($whatmd5) { + if (tlmd5($what) eq $whatmd5) { + $gotfiledone = 1; + } else { + tlwarn("Downloaded file present, size equal, but md5sum differs\nredownloading $what!\n"); + } + } else { + # size ok, no md5sum + tlwarn("Downloaded container present, size equal, but no md5sum available. Hope that is fine!\n"); + $gotfiledone = 1; + } + } else { + tlwarn("Partial download of $what found, removing it!\n"); + unlink($tarfile, $lzmafile); + } } else { - tlwarn("Partial download of $what found, removing it!\n"); - unlink($tarfile, $lzmafile); + # ok no size information, hopefully we have md5 sums + if ($whatmd5) { + if (tlmd5($what) eq $whatmd5) { + $gotfiledone = 1; + } else { + tlwarn("Downloaded file present, but md5sum differs, removing it!\n"); + } + } else { + tlwarn("container found, but we cannot verify size of md5sum!\nContinuing with it and hope that it is ok!\n"); + $gotfiledone = 1; + } } + debug("Reusing already downloaded container $lzmafile\n") + if ($gotfiledone); } if (!$gotfiledone) { if ($what =~ m,http://|ftp://,) { @@ -1448,6 +1478,18 @@ sub give_ctan_mirror { return($mirror); } +sub tlmd5 { + my $file = shift; + if (-r $file) { + open(FILE, $file) or die "Can't open '$file': $!"; + binmode(FILE); + return Digest::MD5->new->addfile(*FILE)->hexdigest; + close(FILE); + } else { + return ""; + } +} + ############################################# # # Taken from Text::ParseWords |