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