# HG changeset patch # User cin # Date 1382405760 -14400 # Node ID 30a88ad2b2fdf5f40aa21f284ce71ba87024d3a1 # Parent 93b83e3c38d60cc9b3b2a7f495e8f9d1ff0ecb2d added validation mode and automatic errors fixing diff -r 93b83e3c38d6 -r 30a88ad2b2fd _test/read_repo.pl --- 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) = @_;