#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
use DistroDBTools;

my %bin_exclude_files = map {$_ => 1} qw!
binary/10-distrodb-old.txt
binary/20-manual-old.txt
binary/40-distrodb-new.txt
binary/40-distrodb.txt
!;

my %src_exclude_files = map {$_ => 1} qw!
source/10-distrodb-old.txt
source/20-manual-old.txt
source/40-distrodb-new.txt
source/40-distrodb.txt
!;

my $distromap_config=&DistroDBTools::read_distromap_config();
my $origin_repo=$distromap_config->{'ORIGINREPO'};
my $origin_branch=$distromap_config->{'ORIGINBRANCH'};
die "can't determine ORIGIN" unless $origin_repo and $origin_branch;
my $ORIGIN=$origin_repo.'/'.$origin_branch;

my (%provides, %source);

&DistroDBTools::read_distrodb_map(\%provides,$ORIGIN,'provides');
&extract_old('binary',\%bin_exclude_files,\%provides,'old');

&DistroDBTools::read_distrodb_2nd_column_as_flag(\%source,$ORIGIN,'sourcename');
&extract_old('source',\%src_exclude_files,\%source,'old');

sub extract_old {
    my ($dir, $exclude, $allowed, $suffix)=@_;
    &DistroDBTools::extract_by_subroutine ($dir, $exclude, $suffix, sub {
	my ($filename, $in)=@_;
	return 0 if substr($in,0,1) eq '/';
	return !$allowed->{$in};
    });
}
