1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/usr/bin/perl -w
# OK, here we take a command line argument for dpkg-source, and parse
# out all the .elc files that have been change and delete them so that
# the real dpkg-source (run later by dpkg-buildpackage) won't complain
# about them.
use strict;
use diagnostics;
my $dir = $ARGV[0];
if(0) {
my $prog_name = "dpkg-source -d $dir 2>&1";
open(DPKG_OUTPUT, "$prog_name |");
while (<DPKG_OUTPUT>) {
# look for lines like dpkg-source
if (m/^$prog_name: cannot represent change to (.*\.elc):.*$/) {
print "This NOT OK: $_";
print "Removing $1 cause $prog_name complained\n";
unlink "$dir/$1";
}
else {
print "This OK: $_";
}
}
close(DPKG_OUTPUT);
}
elsif(1) {
print "Searching directory ", $ARGV[0], "\n";
chdir $ARGV[0] || die "No directory $1";
my $prog_name = "find . -name *.elc -print";
open(FIND_OUTPUT, "$prog_name |");
my %stats = ();
my $total_files = 0;
while(<FIND_OUTPUT>) {
chop;
my @one_stats = stat($_);
$stats{$_} = $one_stats[9];
$total_files++;
# print "Checking file $_\n";
}
close(FIND_OUTPUT);
# cound up all the available times.
my %times = ();
my $one_time;
foreach $one_time (values %stats) {
if(! exists $times{$one_time}) {
$times{$one_time} = 0;
}
$times{$one_time}++;
}
# find the most often occuring time
my $max_time = 0;
my $time_number = "";
foreach $one_time (keys %times) {
if($times{$one_time} > $max_time) {
$max_time = $times{$one_time};
$time_number = $one_time;
}
}
# OK unlink all the files with times greater than $time_number
my $one_file;
my $unlinked_files = 0;
foreach $one_file (keys %stats) {
if($stats{$one_file} > $time_number) {
unlink($one_file);
print "Unlinking $one_file. ", $stats{$one_file}, " > $time_number\n";
$unlinked_files++;
}
}
print "Unlinked $unlinked_files out of $total_files\n";
# let's hope that clears out all the modified stuff.
}
exit 0;
|