timestamp.pl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. use strict;
  9. sub get_ts($$) {
  10. my $path = shift;
  11. my $options = shift;
  12. my $ts = 0;
  13. my $fn = "";
  14. open FIND, "find $path -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |";
  15. while (<FIND>) {
  16. chomp;
  17. my $file = $_;
  18. next if -l $file;
  19. my @stat = stat $file;
  20. if ($stat[9] > $ts) {
  21. $ts = $stat[9];
  22. $fn = $file;
  23. }
  24. }
  25. close FIND;
  26. return ($ts, $fn);
  27. }
  28. (@ARGV > 0) or push @ARGV, ".";
  29. my $ts = 0;
  30. my $n = ".";
  31. my %options;
  32. while (@ARGV > 0) {
  33. my $path = shift @ARGV;
  34. if ($path =~ /^-x/) {
  35. my $str = shift @ARGV;
  36. $options{"findopts"} .= " -and -not -path \\*".$str."\\*"
  37. } elsif ($path =~ /^-f/) {
  38. $options{"findopts"} .= " -follow";
  39. } elsif ($path =~ /^-/) {
  40. $options{$path} = 1;
  41. } else {
  42. my ($tmp, $fname) = get_ts($path, $options{"findopts"});
  43. if ($tmp > $ts) {
  44. if ($options{'-f'}) {
  45. $n = $fname;
  46. } else {
  47. $n = $path;
  48. }
  49. $ts = $tmp;
  50. }
  51. }
  52. }
  53. if ($options{"-p"}) {
  54. print "$n\n";
  55. } elsif ($options{"-t"}) {
  56. print "$ts\n";
  57. } else {
  58. print "$n\t$ts\n";
  59. }