#!/usr/bin/perl

use Archive::Cpio;
use Getopt::Long;

=head1 NAME

cpio-filter - transform a cpio archive

=head1 SYNOPSIS

    urpmi [--exclude <PATTERN>]

=head1 DESCRIPTION

Transform a cpio archive on the fly. Reads on stdin and output on stderr

=head1 AUTHOR

Pascal Rigaux <pixel@mandriva.com>

=cut

my %options = (
    'exclude=s' => \ (my $exclude), 
);

sub usage {
    die "usage: cpio-filter [--exclude <PATTERN>]\n";
}

GetOptions(%options) or usage();
@ARGV == 0 or usage();

while (my $e = Archive::Cpio::read_one(\*STDIN)) {
    if ($exclude && $e->{name} =~ m!(^|/)${exclude}($|/)!) {
	next;
    }

    Archive::Cpio::write_one(\*STDOUT, $e);
}
Archive::Cpio::write_trailer(\*STDOUT);
