#!/usr/bin/perl

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

my %bin_exclude_files = map {$_ => 1} qw!
binary/40-distrodb-new.txt
binary/40-distrodb.txt
!, glob 'binary/*-nodest.txt';

my %src_exclude_files = map {$_ => 1} qw!
source/40-distrodb-new.txt
source/40-distrodb.txt
!, glob 'source/*-nodest.txt';

my $DEST='altlinux/sisyphus';

my (%provides, %source);

&DistroDBTools::read_distrodb_map(\%provides,$DEST,'provides');
&extract_not_allowed('binary',\%bin_exclude_files,\%provides,'nodest');

&DistroDBTools::read_distrodb_2nd_column_as_flag(\%source,$DEST,'sourcename');
&extract_not_allowed('source',\%src_exclude_files,\%source,'nodest');

sub extract_not_allowed {
    my ($dir, $exclude, $allowed, $suffix)=@_;
    &DistroDBTools::extract_by_subroutine ($dir, $exclude, $suffix, sub {
	my ($filename, @in)=@_;
	my $notallowed=0;
	# substr($_,0,1) eq '/' -- binary filepath provides as /bin/sh
	map {$notallowed=1 if !$allowed->{$_} and not substr($_,0,1) eq '/'} @in[1..$#in];
	return $notallowed;
   });
}
