Product SiteDocumentation Site

Listing the Files In A Package

The files subroutine provides a list of all the files in a package. Listing 18-7 shows how to access this list.
Listing 18-7: rpmfiles.pl
#!/usr/bin/perl
#
# Queries RPM database for given package,
# prints out the files in the package.
# Usage:
# rpmfiles.pl package_name
#
use strict;
use RPM2;
my $rpm_db = RPM2->open_rpm_db();
my $pkg_iter = $rpm_db->find_by_name_iter( $ARGV[0] );
while (my $pkg = $pkg_iter->next() ) {
printFiles( $pkg );
}
$rpm_db->close_rpm_db();
# Prints installation data for one package.
sub printFiles {
my($pkg) = shift;
my $files = arrayToString("\n", $pkg->files() );
print "Files:\n", $files, "\n";
}
sub arrayToString {
my($sep) = shift;
my(@array) = @_;
my($str);
$str = $array[0];
for ( my $i = 1; $i < $#array; $i++ )
{
$str = $str . $sep . $array[$i];
}
return $str;
}
When you run this script, you’ll see output like the following:
$ ./rpmfiles.pl jikes
Files:
/usr/bin/jikes
/usr/doc/jikes-1.17/license.htm