timestamp.pl 1.2 KB

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