Mercurial > pub > Yours
comparison _test/read_repo.pl @ 1:30a88ad2b2fd
added validation mode and automatic errors fixing
| author | cin |
|---|---|
| date | Tue, 22 Oct 2013 05:36:00 +0400 |
| parents | 93b83e3c38d6 |
| children | f2a86753b494 |
comparison
equal
deleted
inserted
replaced
| 0:93b83e3c38d6 | 1:30a88ad2b2fd |
|---|---|
| 28 ); | 28 ); |
| 29 | 29 |
| 30 my $repoUrl = | 30 my $repoUrl = |
| 31 'http://download.opensuse.org/repositories/Mono/openSUSE_12.3/'; | 31 'http://download.opensuse.org/repositories/Mono/openSUSE_12.3/'; |
| 32 my $repoDir = 'repo'; | 32 my $repoDir = 'repo'; |
| 33 my $validate = 0; | |
| 33 | 34 |
| 34 my $agent = UserAgent->new(); | 35 my $agent = UserAgent->new(); |
| 35 $agent->env_proxy(); | 36 $agent->env_proxy(); |
| 36 | 37 |
| 37 # список файлов, которые должны быть в репозитарии, заполняется по мере загрузки/проверки целостности | 38 # список файлов, которые должны быть в репозитарии, заполняется по мере загрузки/проверки целостности |
| 52 $mdLocation, | 53 $mdLocation, |
| 53 "repodata/repomd.xml.asc", | 54 "repodata/repomd.xml.asc", |
| 54 "repodata/repomd.xml.key" | 55 "repodata/repomd.xml.key" |
| 55 ); | 56 ); |
| 56 | 57 |
| 57 foreach my $initLocation (@initial) { | 58 $files{MakeLocalName($_)} = { location => "${repoUrl}$_" } foreach @initial; |
| 58 my $file = MakeLocalName($initLocation); | 59 |
| 59 $files{$file} = { location => "${repoUrl}$initLocation"}; | 60 unless ($validate) { |
| 60 my $resp = $agent->get( | 61 foreach my $initLocation (@initial) { |
| 61 "${repoUrl}$initLocation", | 62 my $file = MakeLocalName($initLocation); |
| 62 ':content_file' => $file | 63 my $resp = $agent->get( |
| 63 ); | 64 "${repoUrl}$initLocation", |
| 64 | 65 ':content_file' => $file |
| 65 die "failed to load metadata $initLocation: ", $resp->code, " ", $resp->message | 66 ); |
| 66 unless $resp->is_success; | 67 |
| 68 die "failed to load metadata $initLocation: ", $resp->code, " ", $resp->message | |
| 69 unless $resp->is_success; | |
| 70 } | |
| 67 } | 71 } |
| 68 | 72 |
| 69 my $parser = MDParser->new(); | 73 my $parser = MDParser->new(); |
| 70 $parser->Parse( { location => $mdFile, no_blanks => 1 } ); | 74 $parser->Parse( { location => $mdFile, no_blanks => 1 } ); |
| 71 | 75 |
| 132 } | 136 } |
| 133 } | 137 } |
| 134 | 138 |
| 135 print "validating\n"; | 139 print "validating\n"; |
| 136 | 140 |
| 141 my @bad; | |
| 142 | |
| 137 while(my ($file,$md) = each %files) { | 143 while(my ($file,$md) = each %files) { |
| 138 if (my $checksum = $md->{checksum}) { | 144 if (my $checksum = $md->{checksum}) { |
| 139 if( my $type = $digestTypes{lc($checksum->{type})} ) { | 145 if( my $type = $digestTypes{lc($checksum->{type})} ) { |
| 140 if(open my $hfile, "<$file") { | 146 if(open my $hfile, "<$file") { |
| 141 binmode $hfile; | 147 binmode $hfile; |
| 144 | 150 |
| 145 print "\t$file: $digest ne $checksum->{value}\n"; | 151 print "\t$file: $digest ne $checksum->{value}\n"; |
| 146 } else { | 152 } else { |
| 147 print "\t$file: ", -f $file ? "unable to open" : "missing","\n"; | 153 print "\t$file: ", -f $file ? "unable to open" : "missing","\n"; |
| 148 } | 154 } |
| 155 push @bad,$md; | |
| 149 } else { | 156 } else { |
| 150 print "\t$file: unknown hash algorithm: $checksum->{type}\n"; | 157 print "\t$file: unknown hash algorithm: $checksum->{type}\n"; |
| 151 } | 158 } |
| 152 } | 159 } |
| 153 } | 160 } |
| 154 | 161 |
| 155 print "files: ", scalar keys %files, "\n"; | 162 print "fixing\n"; |
| 156 print "dirs: ", scalar keys %dirs, "\n"; | 163 |
| 157 getc; | 164 foreach my $md (@bad) { |
| 165 my $location = $md->{location}; | |
| 166 | |
| 167 my $file = MakeLocalName($location); | |
| 168 | |
| 169 my $size = sprintf("%0.2fM",$md->{size}/(1024*1024)); | |
| 170 print "\tfetch $location [${size}]\n"; | |
| 171 | |
| 172 $agent->get("${repoUrl}$location", ":content_file" => $file); | |
| 173 } | |
| 174 | |
| 175 print "total files: ", scalar keys %files, "\n"; | |
| 158 | 176 |
| 159 sub MakeLocalName { | 177 sub MakeLocalName { |
| 160 my ($url) = @_; | 178 my ($url) = @_; |
| 161 | 179 |
| 162 my @parts = split /\//, $url; | 180 my @parts = split /\//, $url; |
