Update of /cvsroot/fink/fink/perlmod/Fink In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25521
Modified Files: ChangeLog Checksum.pm NetAccess.pm PkgVersion.pm Log Message: Re-add external API for looking up checksums of a file. Index: PkgVersion.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v retrieving revision 1.482 retrieving revision 1.483 diff -u -d -r1.482 -r1.483 --- PkgVersion.pm 17 Oct 2005 16:44:03 -0000 1.482 +++ PkgVersion.pm 18 Oct 2005 01:45:42 -0000 1.483 @@ -2903,10 +2903,13 @@ if (not Fink::Checksum->validate($found_archive, $self->get_checksum($suffix))) { # mismatch, ask user what to do $tries++; + + my %archive_sums = %{Fink::Checksum->get_all_checksums($found_archive)}; my $sel_intro = "The checksum of the file $archive of package ". $self->get_fullname()." is incorrect. The most likely ". "cause for this is a corrupted or incomplete download\n". - "Expected: $checksum\nActual: $found_archive_sum\n". + "Expected: $checksum\nActual: " . + join(" ", map "$_($archive_sums{$_})\n", sort keys %archive_sums) . "It is recommended that you download it ". "again. How do you want to proceed?"; $answer = &prompt_selection("Make your choice: ", Index: Checksum.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/Checksum.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Checksum.pm 17 Oct 2005 16:30:53 -0000 1.3 +++ Checksum.pm 18 Oct 2005 01:45:42 -0000 1.4 @@ -136,10 +136,32 @@ die "no checksum module loaded\n"; } +=item get_all_checksums($filename) - get all possible checksums for a file + +This class method returns a ref to a hash of algorithm=>checksum pairs +for all available algorithms for the given $filename. + +=cut + +sub get_all_checksums { + my $class = shift; + my $filename = shift; + + my %checksums; + + foreach my $algorithm ( find_subpackages($class) ) { + $algorithm =~ s/${class}:://; + my $plugin = Fink::Checksum->new($algorithm); + $checksums{$algorithm} = $plugin->get_checksum($filename) if defined $plugin; + } + + return \%checksums; +} + =item validate($filename, $checksum, [$algorithm]) - validate a file -Validate that the $checksum for file $filename validates, when -using $algorithm. +Returns a boolean indicating whether the $checksum for file $filename +is correctw hen using $algorithm.0 If $checksum is specified in the format used in the Source-Checksum field (ie, the MD5(string) format), then $algorithm will be detected @@ -153,9 +175,7 @@ my $checksum = shift; my $algorithm = shift; - if ($checksum =~ /^\s*(\w+)\((\w+)\)\s*$/) { - ($algorithm, $checksum) = ($1, $2); - } + ($algorithm, $checksum) = $class->parse_checksum($checksum, $algorithm); #print "validating $algorithm($checksum) for $filename\n"; my $plugin = Fink::Checksum->new($algorithm); @@ -167,6 +187,36 @@ return undef; } +=item parse_checksum($checksum, [$algorithm]) - tease apart different syntaxes + +This class method returns a (algorithm=>checksum) pair. If the passed +$checksum has the form of ALGORITHM(CHECKSUM), the ALGORITHM and +CHECKSUM components are returned separately. If the passed $checksum +is just a checksum string, $algorithm is used as the algorithm. If the +algorithm is not contained in the passed $checksum and no $algorithm +is passed, "MD5" is returned as the algorithm. + +=cut + +sub parse_checksum { + my $class = shift; + my $checksum = shift; + my $algorithm = shift || ''; + + if ($checksum =~ /^\s*(\w+)\((\w+)\)\s*$/) { + # first try to pull apart ALGORITHM(CHECKSUM) + ($algorithm, $checksum) = ($1, $2); + } elsif (length $algorithm) { + # next try separate ALGORITHM parameter + $algorithm = $algorithm; + } else { + # nothing yet? default to MD5 + $algorithm = 'MD5'; + } + + return ($algorithm=>$checksum); +} + =item list_plugins() - list the available checksum plugins This method will list the available checksum plugins for Index: NetAccess.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/NetAccess.pm,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- NetAccess.pm 17 Oct 2005 16:12:23 -0000 1.46 +++ NetAccess.pm 18 Oct 2005 01:45:42 -0000 1.47 @@ -79,7 +79,6 @@ my $checksum = shift; my ($http_proxy, $ftp_proxy); my ($url, $cmd, $cont_cmd, $result, $cmd_url); - my $found_archive_sum; # create destination directory if necessary if (not -d $downloaddir) { @@ -196,9 +195,11 @@ $checksum_msg = " and its checksum matches. "; $default_value = "use_it"; # checksum matches: assume okay to use it } else { + my %archive_sums = %{Fink::Checksum->get_all_checksums($file)}; $checksum_msg = " but its checksum does not match. The most likely ". "cause for this is a corrupted or incomplete download\n". - "Expected: $checksum \nActual: $found_archive_sum \n"; + "Expected: $checksum\nActual: " . + join(" ", map "$_($archive_sums{$_})\n", sort keys %archive_sums); } } $result = &prompt_selection("How do you want to proceed?", @@ -264,9 +265,11 @@ # failure, continue loop } else { if (defined $checksum and (not Fink::Checksum->validate($file, $checksum))) { + my %archive_sums = %{Fink::Checksum->get_all_checksums($file)}; &print_breaking("The checksum of the file is incorrect. The most likely ". "cause for this is a corrupted or incomplete download\n". - "Expected: $checksum \nActual: $found_archive_sum \n"); + "Expected: $checksum\nActual: " . + join(" ", map "$_($archive_sums{$_})\n", sort keys %archive_sums)); # checksum failure, continue loop } else { # success, return to caller Index: ChangeLog =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v retrieving revision 1.1170 retrieving revision 1.1171 diff -u -d -r1.1170 -r1.1171 --- ChangeLog 17 Oct 2005 16:12:23 -0000 1.1170 +++ ChangeLog 18 Oct 2005 01:45:42 -0000 1.1171 @@ -1,3 +1,9 @@ +2005-10-17 Daniel Macks <[EMAIL PROTECTED]> + + * Checksum.pm: new class methods get_all_checksums and parse_checksum. + NetAccess.pm, PkgVersion.pm: use get_all_checksums to look up + actual checksum when it doesn't match expected. + 2005-10-17 Benjamin Reed <[EMAIL PROTECTED]> * Bootstrap.pm, Checksum.pm, Engine.pm, NetAccess.pm, PkgVersion.pm, ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ Fink-commits mailing list Fink-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fink-commits