fix shell escaping bug in append() function
[openwrt.git] / scripts / timestamp.pl
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2006 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 use strict;
10
11 sub get_ts($$) {
12 my $path = shift;
13 my $options = shift;
14 my $ts = 0;
15 my $fn = "";
16 open FIND, "find $path -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |";
17 while (<FIND>) {
18 chomp;
19 my $file = $_;
20 open FILE, "<$file";
21 my @stat = stat FILE;
22 close FILE;
23 if ($stat[9] > $ts) {
24 $ts = $stat[9];
25 $fn = $file;
26 }
27 }
28 close FIND;
29 return ($ts, $fn);
30 }
31
32 (@ARGV > 0) or push @ARGV, ".";
33 my $ts = 0;
34 my $n = ".";
35 my %options;
36 while (@ARGV > 0) {
37 my $path = shift @ARGV;
38 if ($path =~ /^-x/) {
39 my $str = shift @ARGV;
40 $options{"findopts"} .= " -and -not -path \\*".$str."\\*"
41 } elsif ($path =~ /^-f/) {
42 $options{"findopts"} .= " -follow";
43 } elsif ($path =~ /^-/) {
44 $options{$path} = 1;
45 } else {
46 my ($tmp, $fname) = get_ts($path, $options{"findopts"});
47 if ($tmp > $ts) {
48 if ($options{'-f'}) {
49 $n = $fname;
50 } else {
51 $n = $path;
52 }
53 $ts = $tmp;
54 }
55 }
56 }
57
58 if ($options{"-p"}) {
59 print "$n\n";
60 } elsif ($options{"-t"}) {
61 print "$ts\n";
62 } else {
63 print "$n\t$ts\n";
64 }
This page took 0.047957 seconds and 5 git commands to generate.