+sub versions_time_cleanup {
+ my ($db) = @_;
+ my $time = time;
+ for my $package (keys %{$db}) {
+ my $temp = $db->{$package};
+ for my $dist (keys %{$temp}) {
+ for my $arch (keys %{$temp->{$dist}}) {
+ my @versions = (sort {$temp->{$dist}{$arch}{$a} <=>
+ $temp->{$dist}{$arch}{$b}
+ }
+ keys %{$temp->{$dist}{$arch}});
+ next unless @versions > 1;
+ for my $i (0 .. ($#versions-1)) {
+ last if $temp->{$dist}{$arch}{$versions[$i+1]} >
+ ($time - $config{remove_age}*60*60*24);
+ last if keys %{$temp->{$dist}{$arch}} <= 1;
+ delete $temp->{$dist}{$arch}{$versions[$i]};
+ }
+ }
+ }
+ $db->{$package} = $temp;
+ }
+}