replace find call with perl code

git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@3782 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Mike Baker 2006-05-15 22:42:04 +00:00
parent 6cf19bfcfe
commit d167ad781f
1 changed files with 22 additions and 11 deletions

View File

@ -1,24 +1,35 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use File::stat;
sub crawl($$) {
my $path = shift;
my $options = shift;
my @results = $path;
opendir(DIR,$path);
foreach my $file (readdir(DIR)) {
if ($file !~m/^(\.(svn|\.?)|CVS$options)$/) {
push @results, crawl("$path/$file",$options);
}
}
closedir(DIR);
return @results;
}
sub get_ts($$) { sub get_ts($$) {
my $path = shift; my $path = shift;
my $options = shift; my $options = shift;
my $ts = 0; my $ts = 0;
my $fn = ""; my $fn = "";
open FIND, "find $path -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |"; my @search = crawl($path,$options);
while (<FIND>) { while (@search) {
chomp; my $file = shift @search;
my $file = $_; my $mtime = stat($file)->mtime;
open FILE, "<$file"; if ($mtime > $ts) {
my @stat = stat FILE; $ts = $mtime;
close FILE;
if ($stat[9] > $ts) {
$ts = $stat[9];
$fn = $file; $fn = $file;
} }
} }
close FIND;
return ($ts, $fn); return ($ts, $fn);
} }
@ -30,7 +41,7 @@ while (@ARGV > 0) {
my $path = shift @ARGV; my $path = shift @ARGV;
if ($path =~ /^-x/) { if ($path =~ /^-x/) {
my $str = shift @ARGV; my $str = shift @ARGV;
$options{"-x"} .= " -and -not -path \\*".$str."\\*" $options{"-x"} .= "|".$str;
} elsif ($path =~ /^-/) { } elsif ($path =~ /^-/) {
$options{$path} = 1; $options{$path} = 1;
} else { } else {