]> git.pld-linux.org Git - projects/cleanbuild.git/blob - findunusedbr
- "GCONF_SCHEMAS_INSTALL" => "GConf2-devel"
[projects/cleanbuild.git] / findunusedbr
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 die "Arguments missing: $0 [-c] <chroot> <spec>\n" unless @ARGV;
7 my $clear;
8 if ( $ARGV[0] eq "-c" ) {
9         $clear = 1;
10         shift @ARGV;
11 }
12 my $chroot = shift @ARGV or die "chroot directory not specified\n";
13 my $spec = shift @ARGV or die "Spec file not specified\n";
14
15 -d $chroot or die "chroot '$chroot' is not a directory\n";
16 -r $spec or die "spec file '$spec' is not readable\n";
17
18 my @rpms;
19 open F_IN, "<", $spec or die "Cannot open '$spec'\n";
20 while ( <F_IN> ) {
21         if ( /^\s*(?:%{.*)?BuildRequires:\s*(\S+)/i ) {
22                 local $_ = $1;
23                 s/}$//;
24                 push @rpms, $_;
25         } elsif ( /^%(prep|build|changelog)/ ) {
26                 last;
27         }
28 }
29 close F_IN;
30
31 sub clear_files
32 {
33         my $rpm = shift;
34         my $files = shift;
35         foreach my $file ( @$files ) {
36                 chop $file;
37                 my $f = $chroot.$file;
38
39                 local $_;
40                 while ( $_ = readlink $f and m#^/# ) {
41                          $f = $chroot.$_;
42                 }
43
44                 # XXX: this truncates mtime to its low resolution value
45                 my $mtime = (stat $f)[9];
46                 warn "Mtime failed on $f" unless $mtime;
47                 utime 0, $mtime, $f;
48         }
49 }
50
51 sub check_files
52 {
53         my $rpm = shift;
54         my $files = shift;
55         #my $used = 0;
56         foreach my $file ( @$files ) {
57                 chop $file;
58                 my $f = $chroot.$file;
59
60                 local $_;
61                 while ( $_ = readlink $f and m#^/# ) {
62                          $f = $chroot.$_;
63                 }
64
65                 my $atime = (stat $f)[8];
66                 if ( not defined $atime ) {
67                         print "$rpm: $f no atime\n";
68                 } elsif ( $atime > 0 ) {
69                         #print "$rpm: $file accessed\n";
70                         #$used = 1;
71                         return;
72                 } else {
73                         #print "$rpm: $file NOT accessed !\n";
74                 }
75         }
76         print "$rpm may be superfluous !\n";# unless $used;
77 }
78
79
80 foreach my $rpm ( @rpms ) {
81         my @files = qx/rpm --root=$chroot -ql --what-provides "$rpm"/;
82         next if $files[0] =~ /^no package provides/;
83         #print "*** $rpm ***\n";
84         if ( $clear ) {
85                 clear_files( $rpm, \@files );
86         } else {
87                 check_files( $rpm, \@files );
88         }
89         #print "\n\n";
90 }
This page took 0.074786 seconds and 3 git commands to generate.