2006-04-20 02:25:17 +02:00
|
|
|
#!/usr/bin/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 = "";
|
2006-05-16 01:04:02 +02:00
|
|
|
open FIND, "find $path -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |";
|
|
|
|
while (<FIND>) {
|
|
|
|
chomp;
|
|
|
|
my $file = $_;
|
|
|
|
open FILE, "<$file";
|
|
|
|
my @stat = stat FILE;
|
|
|
|
close FILE;
|
|
|
|
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;
|
2006-08-04 23:42:29 +02:00
|
|
|
$options{"findopts"} .= " -and -not -path \\*".$str."\\*"
|
|
|
|
} elsif ($path =~ /^-f/) {
|
|
|
|
$options{"findopts"} .= " -follow";
|
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) {
|
2006-04-20 05:45:03 +02:00
|
|
|
if ($options{'-f'}) {
|
|
|
|
$n = $fname;
|
|
|
|
} else {
|
|
|
|
$n = $path;
|
|
|
|
}
|
2006-04-20 02:25:17 +02:00
|
|
|
$ts = $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($options{"-p"}) {
|
|
|
|
print "$n\n";
|
|
|
|
} elsif ($options{"-t"}) {
|
|
|
|
print "$ts\n";
|
|
|
|
} else {
|
|
|
|
print "$n\t$ts\n";
|
|
|
|
}
|