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
|
#!/usr/local/bin/perl
#
# given a dir, suck in all the executable files in there
#
require "realpath.pl";
sub suck_exes {
local($dir) = @_;
print "Going into suck_exes with dir $dir\n" if $verbose;
#
# we cache dirs, no sense in working too hard
#
if (defined($all_dirs_exes{$dir})) {
print "already processed $dir\n" if $debug;
return;
}
$all_dirs_exes{$dir} = $dir;
# ignore proc, bad news in there...
return if ($dir =~ /^\/proc\//);
if (!opendir(DIR, $dir)) {
warn "Can't open $dir (in suck_exes())\n";
return;
}
#
# look at each file in the dir; have we seen it before?
#
while (($file = readdir(DIR))) {
print "Looking at: $dir/$file " if $debug;
#
# get the honest-to-god path for (symlinks) - this really slows
# things down
#
$real_file = &realpath("$dir/$file") if ("$dir/$file" =~ /^\//);
print "($real_file)\n" if $debug;
# next if it isn't an executable file
next unless (-x $real_file && -f $real_file);
print "executable $dir/file - $real_file\n" if $debug;
# collision detector
if (defined($all_exes{$file})) {
print "collision... $file already seen ($all_exes{$file})\n"
if $debug;
}
$all_exes{$file} = $file;
$all_location_exes{$file} = $real_file;
# do we want this? I think so... (for sym links)
$all_location_exes{$file} = "$dir/$file";
}
closedir(DIR);
}
1;
|