2008-09-23 20:29:44 +02:00
|
|
|
#!/usr/bin/env perl
|
2006-06-27 02:35:46 +02: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 02:25:17 +02:00
|
|
|
use strict;
|
|
|
|
|
2006-04-20 05:45:03 +02:00
|
|
|
sub get_ts($$) {
|
2006-04-20 02:25:17 +02:00
|
|
|
my $path = shift;
|
2006-04-20 05:45:03 +02:00
|
|
|
my $options = shift;
|
2006-04-20 02:25:17 +02:00
|
|
|
my $ts = 0;
|
2006-04-20 05:45:03 +02:00
|
|
|
my $fn = "";
|
2007-08-30 23:12:39 +02:00
|
|
|
open FIND, "find $path -type f -and -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |";
|
2006-05-16 01:04:02 +02:00
|
|
|
while (<FIND>) {
|
|
|
|
chomp;
|
|
|
|
my $file = $_;
|
2007-01-12 12:09:05 +01:00
|
|
|
next if -l $file;
|
|
|
|
my @stat = stat $file;
|
2006-05-16 01:04:02 +02:00
|
|
|
if ($stat[9] > $ts) {
|
|
|
|
$ts = $stat[9];
|
2006-04-20 05:45:03 +02:00
|
|
|
$fn = $file;
|
|
|
|
}
|
2006-04-20 02:25:17 +02:00
|
|
|
}
|
2006-05-16 01:04:02 +02:00
|
|
|
close FIND;
|
2006-04-20 05:45:03 +02:00
|
|
|
return ($ts, $fn);
|
2006-04-20 02:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(@ARGV > 0) or push @ARGV, ".";
|
|
|
|
my $ts = 0;
|
|
|
|
my $n = ".";
|
|
|
|
my %options;
|
2006-04-20 05:45:03 +02:00
|
|
|
while (@ARGV > 0) {
|
|
|
|
my $path = shift @ARGV;
|
|
|
|
if ($path =~ /^-x/) {
|
|
|
|
my $str = shift @ARGV;
|
2007-08-30 23:12:39 +02:00
|
|
|
$options{"findopts"} .= " -and -not -path '".$str."'"
|
2006-08-04 23:42:29 +02:00
|
|
|
} elsif ($path =~ /^-f/) {
|
|
|
|
$options{"findopts"} .= " -follow";
|
2007-08-29 05:51:49 +02:00
|
|
|
} elsif ($path =~ /^-n/) {
|
|
|
|
my $arg = $ARGV[0];
|
|
|
|
$options{$path} = $arg;
|
2006-04-20 05:45:03 +02:00
|
|
|
} elsif ($path =~ /^-/) {
|
2006-04-20 02:25:17 +02:00
|
|
|
$options{$path} = 1;
|
|
|
|
} else {
|
2006-08-04 23:42:29 +02:00
|
|
|
my ($tmp, $fname) = get_ts($path, $options{"findopts"});
|
2006-04-20 02:25:17 +02:00
|
|
|
if ($tmp > $ts) {
|
2007-09-03 07:02:05 +02:00
|
|
|
if ($options{'-F'}) {
|
2006-04-20 05:45:03 +02:00
|
|
|
$n = $fname;
|
|
|
|
} else {
|
|
|
|
$n = $path;
|
|
|
|
}
|
2006-04-20 02:25:17 +02:00
|
|
|
$ts = $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-29 05:51:49 +02:00
|
|
|
if ($options{"-n"}) {
|
|
|
|
exit ($n eq $options{"-n"} ? 0 : 1);
|
|
|
|
} elsif ($options{"-p"}) {
|
2006-04-20 02:25:17 +02:00
|
|
|
print "$n\n";
|
|
|
|
} elsif ($options{"-t"}) {
|
|
|
|
print "$ts\n";
|
|
|
|
} else {
|
|
|
|
print "$n\t$ts\n";
|
|
|
|
}
|