Mercurial > pub > Yours
changeset 1:30a88ad2b2fd
added validation mode and automatic errors fixing
author | cin |
---|---|
date | Tue, 22 Oct 2013 05:36:00 +0400 |
parents | 93b83e3c38d6 |
children | f2a86753b494 |
files | _test/read_repo.pl |
diffstat | 1 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/_test/read_repo.pl Tue Oct 22 05:26:56 2013 +0400 +++ b/_test/read_repo.pl Tue Oct 22 05:36:00 2013 +0400 @@ -30,6 +30,7 @@ my $repoUrl = 'http://download.opensuse.org/repositories/Mono/openSUSE_12.3/'; my $repoDir = 'repo'; +my $validate = 0; my $agent = UserAgent->new(); $agent->env_proxy(); @@ -54,16 +55,19 @@ "repodata/repomd.xml.key" ); -foreach my $initLocation (@initial) { - my $file = MakeLocalName($initLocation); - $files{$file} = { location => "${repoUrl}$initLocation"}; - my $resp = $agent->get( - "${repoUrl}$initLocation", - ':content_file' => $file - ); - - die "failed to load metadata $initLocation: ", $resp->code, " ", $resp->message - unless $resp->is_success; +$files{MakeLocalName($_)} = { location => "${repoUrl}$_" } foreach @initial; + +unless ($validate) { + foreach my $initLocation (@initial) { + my $file = MakeLocalName($initLocation); + my $resp = $agent->get( + "${repoUrl}$initLocation", + ':content_file' => $file + ); + + die "failed to load metadata $initLocation: ", $resp->code, " ", $resp->message + unless $resp->is_success; + } } my $parser = MDParser->new(); @@ -134,6 +138,8 @@ print "validating\n"; +my @bad; + while(my ($file,$md) = each %files) { if (my $checksum = $md->{checksum}) { if( my $type = $digestTypes{lc($checksum->{type})} ) { @@ -146,15 +152,27 @@ } else { print "\t$file: ", -f $file ? "unable to open" : "missing","\n"; } + push @bad,$md; } else { print "\t$file: unknown hash algorithm: $checksum->{type}\n"; } } } -print "files: ", scalar keys %files, "\n"; -print "dirs: ", scalar keys %dirs, "\n"; -getc; +print "fixing\n"; + +foreach my $md (@bad) { + my $location = $md->{location}; + + my $file = MakeLocalName($location); + + my $size = sprintf("%0.2fM",$md->{size}/(1024*1024)); + print "\tfetch $location [${size}]\n"; + + $agent->get("${repoUrl}$location", ":content_file" => $file); +} + +print "total files: ", scalar keys %files, "\n"; sub MakeLocalName { my ($url) = @_;