]> git.pld-linux.org Git - projects/cleanbuild.git/blob - findunusedbr
- NEW: script for finding unused BRs:
[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                 # XXX: this truncates mtime to its low resolution value
40                 my $mtime = (stat $f)[9];
41                 warn "Mtime failed on $f" unless $mtime;
42                 utime 0, $mtime, $f;
43         }
44 }
45
46 sub check_files
47 {
48         my $rpm = shift;
49         my $files = shift;
50         #my $used = 0;
51         foreach my $file ( @$files ) {
52                 chop $file;
53                 my $f = $chroot.$file;
54
55                 my $atime = (stat $f)[8];
56                 if ( $atime > 0 ) {
57                         #print "$rpm: $file accessed\n";
58                         #$used = 1;
59                         return;
60                 } else {
61                         #print "$rpm: $file NOT accessed !\n";
62                 }
63         }
64         print "$rpm may be superfluous !\n";# unless $used;
65 }
66
67
68 foreach my $rpm ( @rpms ) {
69         my @files = qx/rpm --root=$chroot -ql --what-provides "$rpm"/;
70         next if $files[0] =~ /^no package provides/;
71         #print "*** $rpm ***\n";
72         if ( $clear ) {
73                 clear_files( $rpm, \@files );
74         } else {
75                 check_files( $rpm, \@files );
76         }
77         #print "\n\n";
78 }
This page took 0.030225 seconds and 4 git commands to generate.