2006-04-20 00:25:17 +00:00
|
|
|
#!/usr/bin/perl
|
2006-06-27 00:35:46 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
2006-04-20 00:25:17 +00:00
|
|
|
use strict;
|
|
|
|
|
2006-04-20 03:45:03 +00:00
|
|
|
sub get_ts($$) {
|
2006-04-20 00:25:17 +00:00
|
|
|
my $path = shift;
|
2006-04-20 03:45:03 +00:00
|
|
|
my $options = shift;
|
2006-04-20 00:25:17 +00:00
|
|
|
my $ts = 0;
|
2006-04-20 03:45:03 +00:00
|
|
|
my $fn = "";
|
2007-08-30 21:12:39 +00:00
|
|
|
open FIND, "find $path -type f -and -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |";
|
2006-05-15 23:04:02 +00:00
|
|
|
while (<FIND>) {
|
|
|
|
chomp;
|
|
|
|
my $file = $_;
|
2007-01-12 11:09:05 +00:00
|
|
|
next if -l $file;
|
|
|
|
my @stat = stat $file;
|
2006-05-15 23:04:02 +00:00
|
|
|
if ($stat[9] > $ts) {
|
|
|
|
$ts = $stat[9];
|
2006-04-20 03:45:03 +00:00
|
|
|
$fn = $file;
|
|
|
|
}
|
2006-04-20 00:25:17 +00:00
|
|
|
}
|
2006-05-15 23:04:02 +00:00
|
|
|
close FIND;
|
2006-04-20 03:45:03 +00:00
|
|
|
return ($ts, $fn);
|
2006-04-20 00:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(@ARGV > 0) or push @ARGV, ".";
|
|
|
|
my $ts = 0;
|
|
|
|
my $n = ".";
|
|
|
|
my %options;
|
2006-04-20 03:45:03 +00:00
|
|
|
while (@ARGV > 0) {
|
|
|
|
my $path = shift @ARGV;
|
|
|
|
if ($path =~ /^-x/) {
|
|
|
|
my $str = shift @ARGV;
|
2007-08-30 21:12:39 +00:00
|
|
|
$options{"findopts"} .= " -and -not -path '".$str."'"
|
2006-08-04 21:42:29 +00:00
|
|
|
} elsif ($path =~ /^-f/) {
|
|
|
|
$options{"findopts"} .= " -follow";
|
2007-08-29 03:51:49 +00:00
|
|
|
} elsif ($path =~ /^-n/) {
|
|
|
|
my $arg = $ARGV[0];
|
|
|
|
$options{$path} = $arg;
|
2006-04-20 03:45:03 +00:00
|
|
|
} elsif ($path =~ /^-/) {
|
2006-04-20 00:25:17 +00:00
|
|
|
$options{$path} = 1;
|
|
|
|
} else {
|
2006-08-04 21:42:29 +00:00
|
|
|
my ($tmp, $fname) = get_ts($path, $options{"findopts"});
|
2006-04-20 00:25:17 +00:00
|
|
|
if ($tmp > $ts) {
|
2006-04-20 03:45:03 +00:00
|
|
|
if ($options{'-f'}) {
|
|
|
|
$n = $fname;
|
|
|
|
} else {
|
|
|
|
$n = $path;
|
|
|
|
}
|
2006-04-20 00:25:17 +00:00
|
|
|
$ts = $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-29 03:51:49 +00:00
|
|
|
if ($options{"-n"}) {
|
|
|
|
exit ($n eq $options{"-n"} ? 0 : 1);
|
|
|
|
} elsif ($options{"-p"}) {
|
2006-04-20 00:25:17 +00:00
|
|
|
print "$n\n";
|
|
|
|
} elsif ($options{"-t"}) {
|
|
|
|
print "$ts\n";
|
|
|
|
} else {
|
|
|
|
print "$n\t$ts\n";
|
|
|
|
}
|