]>
Commit | Line | Data |
---|---|---|
930195a7 | 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 | ||
c5175c4e | 39 | local $_; |
40 | while ( $_ = readlink $f and m#^/# ) { | |
41 | $f = $chroot.$_; | |
42 | } | |
43 | ||
0d76b670 ER |
44 | # skip missing files, like "%_excludedocs 0" being active |
45 | next unless stat $f; | |
46 | ||
930195a7 | 47 | # XXX: this truncates mtime to its low resolution value |
48 | my $mtime = (stat $f)[9]; | |
49 | warn "Mtime failed on $f" unless $mtime; | |
50 | utime 0, $mtime, $f; | |
51 | } | |
52 | } | |
53 | ||
54 | sub check_files | |
55 | { | |
56 | my $rpm = shift; | |
57 | my $files = shift; | |
58 | #my $used = 0; | |
59 | foreach my $file ( @$files ) { | |
60 | chop $file; | |
61 | my $f = $chroot.$file; | |
62 | ||
c5175c4e | 63 | local $_; |
64 | while ( $_ = readlink $f and m#^/# ) { | |
65 | $f = $chroot.$_; | |
66 | } | |
67 | ||
930195a7 | 68 | my $atime = (stat $f)[8]; |
c5175c4e | 69 | if ( not defined $atime ) { |
70 | print "$rpm: $f no atime\n"; | |
71 | } elsif ( $atime > 0 ) { | |
930195a7 | 72 | #print "$rpm: $file accessed\n"; |
73 | #$used = 1; | |
74 | return; | |
75 | } else { | |
76 | #print "$rpm: $file NOT accessed !\n"; | |
77 | } | |
78 | } | |
79 | print "$rpm may be superfluous !\n";# unless $used; | |
80 | } | |
81 | ||
82 | ||
83 | foreach my $rpm ( @rpms ) { | |
84 | my @files = qx/rpm --root=$chroot -ql --what-provides "$rpm"/; | |
85 | next if $files[0] =~ /^no package provides/; | |
86 | #print "*** $rpm ***\n"; | |
87 | if ( $clear ) { | |
88 | clear_files( $rpm, \@files ); | |
89 | } else { | |
90 | check_files( $rpm, \@files ); | |
91 | } | |
92 | #print "\n\n"; | |
93 | } |